Skip to content

Commit

Permalink
Select validation does not correctly work when handling change event
Browse files Browse the repository at this point in the history
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
whsieh committed Aug 20, 2015
1 parent 308c791 commit dfc4f77
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 2 deletions.
13 changes: 13 additions & 0 deletions LayoutTests/ChangeLog
@@ -1,3 +1,16 @@
2015-08-19 Wenson Hsieh <wenson_hsieh@apple.com>

Select validation does not correctly work when handling change event
https://bugs.webkit.org/show_bug.cgi?id=145869

Reviewed by Dean Jackson.

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.

2015-08-19 Jinyoung Hur <hur.ims@navercorp.com>

GraphicsContext3D::activeTexture should not be called with zero-based index
Expand Down
@@ -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 LayoutTests/fast/forms/onchange-select-check-validity.html
@@ -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>
18 changes: 18 additions & 0 deletions Source/WebCore/ChangeLog
@@ -1,3 +1,21 @@
2015-08-19 Wenson Hsieh <wenson_hsieh@apple.com>

Select validation does not correctly work when handling change event
https://bugs.webkit.org/show_bug.cgi?id=145869

Reviewed by Dean Jackson.

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.

2015-08-19 Jinyoung Hur <hur.ims@navercorp.com>

GraphicsContext3D::activeTexture should not be called with zero-based index
Expand Down
3 changes: 1 addition & 2 deletions Source/WebCore/html/HTMLSelectElement.cpp
Expand Up @@ -901,6 +901,7 @@ void HTMLSelectElement::selectOption(int optionIndex, SelectOptionFlags flags)

scrollToSelection();

updateValidity();
if (usesMenuList()) {
m_isProcessingUserDrivenChange = flags & UserDriven;
if (flags & DispatchChangeEvent)
Expand All @@ -912,8 +913,6 @@ void HTMLSelectElement::selectOption(int optionIndex, SelectOptionFlags flags)
downcast<RenderListBox>(*renderer).selectionChanged();
}
}

updateValidity();
}

int HTMLSelectElement::optionToListIndex(int optionIndex) const
Expand Down

0 comments on commit dfc4f77

Please sign in to comment.