-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Re-design logic for commandfor form-owner combinations
In whatwg/html#9841 the behaviour for commandfor= as a form owner has subtly changed: - <button commandfor=> (implicit submit) that has a form owner now does nothing (so we will log a warning to the console telling the user that this is the case and they should add `type=button` to make it a command button). - <button type=reset command..> and <button type=submit command..> that have a form owner should do the behaviour explicitly laid out by their `type`, and ignore and `command`/`commandfor` attributes semantics. In this case we log a warning to the console telling the user that the command/commandfor are being ignored. To keep changes light here, only the DefaultEventHandler/CommandForElement logic has changed; a more significant refactor might be needed to adjust `type_` to ensure it does not resolve to `kSubmit` implicitly, but that should be handled more delicately, I believe. Bug: 382238696 Change-Id: I7d5583d34a2d615faeed80905816edb3f261d60d Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6070260 Auto-Submit: Keith Cirkel <[email protected]> Reviewed-by: Mason Freed <[email protected]> Commit-Queue: Keith Cirkel <[email protected]> Cr-Commit-Position: refs/heads/main@{#1393810}
- Loading branch information
1 parent
9d05543
commit 3d3ea3a
Showing
3 changed files
with
209 additions
and
7 deletions.
There are no files selected for viewing
64 changes: 64 additions & 0 deletions
64
html/semantics/forms/the-button-element/button-click-resets-with-commandfor.tentative.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<!doctype html> | ||
<meta charset="utf-8" /> | ||
<title>Clicking a button should submit the form</title> | ||
<meta name="author" title="Keith Cirkel" href="mailto:[email protected]" /> | ||
<link | ||
rel="help" | ||
href="https://html.spec.whatwg.org/multipage/#attr-button-type-submit-state" | ||
/> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
|
||
<form id="form"> | ||
<button id="button" type="reset"></button> | ||
</form> | ||
|
||
<script> | ||
const form = document.getElementById("form"); | ||
const button = document.getElementById("button"); | ||
|
||
function resetState() { | ||
button.removeAttribute("commandfor"); | ||
button.removeAttribute("command"); | ||
button.removeAttribute("disabled"); | ||
button.removeAttribute("form"); | ||
button.setAttribute("type", "reset"); | ||
} | ||
|
||
test((t) => { | ||
t.add_cleanup(resetState); | ||
button.setAttribute("command", "--foo"); | ||
|
||
let called = false; | ||
form.addEventListener("reset", (e) => { | ||
called = true; | ||
}); | ||
button.click(); | ||
assert_true(called, "reset should have been dispatched"); | ||
}, "clicking a reset button should trigger a reset (with command attribute)"); | ||
|
||
test((t) => { | ||
t.add_cleanup(resetState); | ||
button.setAttribute("commandfor", "whatever"); | ||
|
||
let called = false; | ||
form.addEventListener("reset", (e) => { | ||
called = true; | ||
}); | ||
button.click(); | ||
assert_true(called, "reset should have been dispatched"); | ||
}, "clicking a button should trigger a reset (with commandfor attribute)"); | ||
|
||
test((t) => { | ||
t.add_cleanup(resetState); | ||
button.setAttribute("command", "--foo"); | ||
button.setAttribute("commandfor", "whatever"); | ||
|
||
let called = false; | ||
form.addEventListener("reset", (e) => { | ||
called = true; | ||
}); | ||
button.click(); | ||
assert_true(called, "reset should have been dispatched"); | ||
}, "clicking a button should trigger a reset (with command and commandfor attribute)"); | ||
</script> |
110 changes: 110 additions & 0 deletions
110
html/semantics/forms/the-button-element/button-click-submits-with-commandfor.tentative.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
<!doctype html> | ||
<meta charset="utf-8" /> | ||
<title>Clicking a button should submit the form</title> | ||
<meta name="author" title="Keith Cirkel" href="mailto:[email protected]" /> | ||
<link | ||
rel="help" | ||
href="https://html.spec.whatwg.org/multipage/#attr-button-type-submit-state" | ||
/> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
|
||
<form id="form"> | ||
<button id="button"></button> | ||
</form> | ||
|
||
<script> | ||
const form = document.getElementById("form"); | ||
const button = document.getElementById("button"); | ||
|
||
function resetState() { | ||
button.removeAttribute("commandfor"); | ||
button.removeAttribute("command"); | ||
button.removeAttribute("disabled"); | ||
button.removeAttribute("form"); | ||
button.removeAttribute("type"); | ||
} | ||
|
||
test((t) => { | ||
t.add_cleanup(resetState); | ||
button.setAttribute("command", "--foo"); | ||
|
||
let called = false; | ||
form.addEventListener("submit", (e) => { | ||
e.preventDefault(); | ||
called = true; | ||
}, { once: true }); | ||
button.click(); | ||
assert_false(called, "submit should not have been dispatched"); | ||
}, "clicking a button (implicit type) should NOT trigger a submit (with command attribute)"); | ||
|
||
test((t) => { | ||
t.add_cleanup(resetState); | ||
button.setAttribute("commandfor", "whatever"); | ||
|
||
let called = false; | ||
form.addEventListener("submit", (e) => { | ||
e.preventDefault(); | ||
called = true; | ||
}, { once: true }); | ||
button.click(); | ||
assert_false(called, "submit should not have been dispatched"); | ||
}, "clicking a button (implicit type) should NOT trigger a submit (with commandfor attribute)"); | ||
|
||
test((t) => { | ||
t.add_cleanup(resetState); | ||
button.setAttribute("command", "--foo"); | ||
button.setAttribute("commandfor", "whatever"); | ||
|
||
let called = false; | ||
form.addEventListener("submit", (e) => { | ||
e.preventDefault(); | ||
called = true; | ||
}, { once: true }); | ||
button.click(); | ||
assert_false(called, "submit should not have been dispatched"); | ||
}, "clicking a button (implicit type) should NOT trigger a submit (with command and commandfor attribute)"); | ||
|
||
test((t) => { | ||
t.add_cleanup(resetState); | ||
button.setAttribute("command", "--foo"); | ||
button.setAttribute("type", "submit"); | ||
|
||
let called = false; | ||
form.addEventListener("submit", (e) => { | ||
e.preventDefault(); | ||
called = true; | ||
}, { once: true }); | ||
button.click(); | ||
assert_true(called, "submit should have been dispatched"); | ||
}, "clicking a button (explicit type=submit) SHOULD trigger a submit (with command attribute)"); | ||
|
||
test((t) => { | ||
t.add_cleanup(resetState); | ||
button.setAttribute("commandfor", "whatever"); | ||
button.setAttribute("type", "submit"); | ||
|
||
let called = false; | ||
form.addEventListener("submit", (e) => { | ||
e.preventDefault(); | ||
called = true; | ||
}, { once: true }); | ||
button.click(); | ||
assert_true(called, "submit should have been dispatched"); | ||
}, "clicking a button (explicit type=submit) SHOULD trigger a submit (with commandfor attribute)"); | ||
|
||
test((t) => { | ||
t.add_cleanup(resetState); | ||
button.setAttribute("command", "--foo"); | ||
button.setAttribute("commandfor", "whatever"); | ||
button.setAttribute("type", "submit"); | ||
|
||
let called = false; | ||
form.addEventListener("submit", (e) => { | ||
e.preventDefault(); | ||
called = true; | ||
}, { once: true }); | ||
button.click(); | ||
assert_true(called, "submit should have been dispatched"); | ||
}, "clicking a button (explicit type=submit) SHOULD trigger a submit (with command and commandfor attribute)"); | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters