ElementInternals-setFormValue-nullish-value.html (1686B)
1 <!DOCTYPE html> 2 <html> 3 <head> 4 <title>ElementInternals.setFormValue(nullish value) should clear submission value</title> 5 <link rel="help" href="https://html.spec.whatwg.org/multipage/custom-elements.html#dom-elementinternals-setformvalue"> 6 <script src="/resources/testharness.js"></script> 7 <script src="/resources/testharnessreport.js"></script> 8 <script> 9 customElements.define("test-form-element", class extends HTMLElement { 10 static formAssociated = true; 11 constructor() { 12 super(); 13 this.i = this.attachInternals(); 14 } 15 }); 16 </script> 17 </head> 18 <body> 19 <form id="form-null"> 20 <test-form-element id="input-null" name="input-null"></test-form-element> 21 </form> 22 23 <form id="form-undefined"> 24 <test-form-element id="input-undefined" name="input-undefined"></test-form-element> 25 </form> 26 27 <script> 28 test(() => { 29 const input = document.getElementById("input-null"); 30 input.i.setFormValue("fail"); 31 input.i.setFormValue(null); 32 const formData = new FormData(document.getElementById("form-null")); 33 assert_false(formData.has("input-null")); 34 }, "ElementInternals.setFormValue(null) clears submission value"); 35 36 test(() => { 37 const input = document.getElementById("input-undefined"); 38 input.i.setFormValue("fail"); 39 input.i.setFormValue(undefined); 40 const formData = new FormData(document.getElementById("form-undefined")); 41 assert_false(formData.has("input-undefined")); 42 }, "ElementInternals.setFormValue(undefined) clears submission value"); 43 </script> 44 </body> 45 </html>