Source code
Revision control
Copy as Markdown
Other Tools
Test Info:
- This WPT test may be referenced by the following Test IDs:
- /html/semantics/selectors/pseudo-classes/valid-invalid-fieldset-disconnected.html - WPT Dashboard Interop Dashboard
<!DOCTYPE html>
<meta charset=utf-8>
<title>Selector: pseudo-classes (:valid, :invalid) on disconnected fieldset element</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<fieldset id=fieldset1>
<input id=input1>
</fieldset>
<fieldset id=fieldset2>
<select id=select1 required multiple>
<option>foo
</select>
</fieldset>
<script>
test(() => {
const fieldset = document.querySelector("#fieldset1");
const input = document.querySelector("#input1");
assert_true(fieldset.matches(":valid"));
assert_false(fieldset.matches(":invalid"));
fieldset.remove();
input.setCustomValidity("foo");
assert_false(fieldset.matches(":valid"));
assert_true(fieldset.matches(":invalid"));
input.setCustomValidity("");
assert_true(fieldset.matches(":valid"));
assert_false(fieldset.matches(":invalid"));
}, "<input> element becomes invalid inside disconnected <fieldset>");
test(() => {
const fieldset = document.querySelector("#fieldset2");
const select = document.querySelector("#select1");
assert_false(fieldset.matches(":valid"));
assert_true(fieldset.matches(":invalid"));
fieldset.remove();
select.required = false;
assert_true(fieldset.matches(":valid"));
assert_false(fieldset.matches(":invalid"));
select.required = true;
select.firstElementChild.selected = true;
assert_true(fieldset.matches(":valid"));
assert_false(fieldset.matches(":invalid"));
}, "<select> element becomes valid inside disconnected <fieldset>");
</script>