checkValidity() on <select required> returns true when <option value=> is moved in the dom
The new check should be still fast, since accessing selected index is trivial and Item() call is just accessing the element from an
nsTArray.
Differential Revision: https://phabricator.services.mozilla.com/D123371
bugzilla-url: https://bugzilla.mozilla.org/show_bug.cgi?id=1725293
gecko-commit: 5d85665d2784d62c2a4397521c1b17d4211834a4
gecko-reviewers: edgar
diff --git a/html/semantics/forms/the-select-element/select-validity.html b/html/semantics/forms/the-select-element/select-validity.html
index 281e859..9f04487 100644
--- a/html/semantics/forms/the-select-element/select-validity.html
+++ b/html/semantics/forms/the-select-element/select-validity.html
@@ -104,4 +104,21 @@
assert_true(select.checkValidity(), "When a required select has an option that is selected and disabled, the select should be considered valid.");
}, "Validation on selects with non-empty disabled option");
+test(function() {
+ var select = document.createElement('select');
+ select.required = true;
+ var placeholder = document.createElement('option');
+ select.appendChild(placeholder);
+ var nonPlaceholder = document.createElement('option');
+ nonPlaceholder.textContent = "non-placeholder-option";
+ select.appendChild(nonPlaceholder);
+
+ assert_false(select.checkValidity(), "If the placeholder label option is selected, required select element shouldn't be valid.");
+ placeholder.remove();
+ assert_true(select.checkValidity(), "If the placeholder label option is removed, required select element should become valid.");
+ select.prepend(placeholder);
+ assert_false(select.checkValidity(), "If the placeholder label option is selected, required select element shouldn't be valid.");
+
+}, "Remove and add back the placeholder label option");
+
</script>