Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Select validation does not correctly work when handling change event
https://bugs.webkit.org/show_bug.cgi?id=145869 Reviewed by Dean Jackson. Source/WebCore: When selecting an option in a <select> with validation that also has an onchange listener, calling checkValidity() for the select within the onchange handler would produce incorrect results and (on a debug build) crash at an assertion. This is because the change events were being dispatched before form validity was updated. Making the validation step come before the change event dispatch fixes this issue. Test: fast/forms/onchange-select-check-validity.html * html/HTMLSelectElement.cpp: (WebCore::HTMLSelectElement::selectOption): Update validity before dispatching change events. LayoutTests: Tests that checkValidity() returns correct results from within the onchange handler of a <select> when the validity of the selected option changes. * fast/forms/onchange-select-check-validity-expected.txt: Added. * fast/forms/onchange-select-check-validity.html: Added. Canonical link: https://commits.webkit.org/166326@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@188672 268f45cc-cd09-0410-ab3c-d52691b4dbfc
- Loading branch information
Showing
5 changed files
with
73 additions
and
2 deletions.
There are no files selected for viewing
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
4 changes: 4 additions & 0 deletions
4
LayoutTests/fast/forms/onchange-select-check-validity-expected.txt
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,4 @@ | ||
|
||
The select's validity was initially false | ||
The select's validity was changed to true | ||
|
37 changes: 37 additions & 0 deletions
37
LayoutTests/fast/forms/onchange-select-check-validity.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,37 @@ | ||
<html> | ||
<head> | ||
<script> | ||
function log(message) { | ||
document.getElementById("console").appendChild(document.createTextNode(message + "\n")); | ||
} | ||
|
||
function setupTest() { | ||
var isValid = null; | ||
var select = document.getElementById("validated-select"); | ||
select.focus(); | ||
function showFormValidity() { | ||
isValid = select.checkValidity(); | ||
} | ||
showFormValidity(); | ||
select.addEventListener("change", showFormValidity); | ||
|
||
if (window.testRunner) { | ||
testRunner.dumpAsText(); | ||
log("The select's validity was initially " + isValid); | ||
eventSender.keyDown("1"); | ||
log("The select's validity was changed to " + isValid); | ||
} | ||
} | ||
</script> | ||
</head> | ||
|
||
<body onload="setupTest()"> | ||
<form> | ||
<select name="validated-select" required="required" id="validated-select"> | ||
<option value="" selected="selected">Select a value</option> | ||
<option value="1">1</option> | ||
</select> | ||
</form> | ||
<pre id="console"></pre> | ||
</body> | ||
</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
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