button-click-resets-with-commandfor.tentative.html (1930B)
1 <!doctype html> 2 <meta charset="utf-8" /> 3 <title>Clicking a button should submit the form</title> 4 <meta name="author" title="Keith Cirkel" href="mailto:wpt@keithcirkel.co.uk" /> 5 <link 6 rel="help" 7 href="https://html.spec.whatwg.org/multipage/#attr-button-type-submit-state" 8 /> 9 <script src="/resources/testharness.js"></script> 10 <script src="/resources/testharnessreport.js"></script> 11 12 <form id="form"> 13 <button id="button" type="reset"></button> 14 </form> 15 16 <script> 17 const form = document.getElementById("form"); 18 const button = document.getElementById("button"); 19 20 function resetState() { 21 button.removeAttribute("commandfor"); 22 button.removeAttribute("command"); 23 button.removeAttribute("disabled"); 24 button.removeAttribute("form"); 25 button.setAttribute("type", "reset"); 26 } 27 28 test((t) => { 29 t.add_cleanup(resetState); 30 button.setAttribute("command", "--foo"); 31 32 let called = false; 33 form.addEventListener("reset", (e) => { 34 called = true; 35 }); 36 button.click(); 37 assert_true(called, "reset should have been dispatched"); 38 }, "clicking a reset button should trigger a reset (with command attribute)"); 39 40 test((t) => { 41 t.add_cleanup(resetState); 42 button.setAttribute("commandfor", "whatever"); 43 44 let called = false; 45 form.addEventListener("reset", (e) => { 46 called = true; 47 }); 48 button.click(); 49 assert_true(called, "reset should have been dispatched"); 50 }, "clicking a button should trigger a reset (with commandfor attribute)"); 51 52 test((t) => { 53 t.add_cleanup(resetState); 54 button.setAttribute("command", "--foo"); 55 button.setAttribute("commandfor", "whatever"); 56 57 let called = false; 58 form.addEventListener("reset", (e) => { 59 called = true; 60 }); 61 button.click(); 62 assert_true(called, "reset should have been dispatched"); 63 }, "clicking a button should trigger a reset (with command and commandfor attribute)"); 64 </script>