Skip to content

Commit

Permalink
Check all associated elements for form validity
Browse files Browse the repository at this point in the history
Closes #2979. Closes #2980.
  • Loading branch information
domenic committed Mar 28, 2021
1 parent 2202703 commit c92f9c1
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/jsdom/living/nodes/HTMLFormElement-impl.js
Expand Up @@ -191,7 +191,7 @@ class HTMLFormElementImpl extends HTMLElementImpl {
// https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#statically-validate-the-constraints
_staticallyValidateConstraints() {
const controls = [];
for (const el of domSymbolTree.treeIterator(this)) {
for (const el of this.elements) {
if (el.form === this && isSubmittable(el)) {
controls.push(el);
}
Expand Down
@@ -0,0 +1,26 @@
<!DOCTYPE html>
<meta charset="utf-8">
<title>Forms outside the form element that use the form="" attribute still get validated</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>

<input id="the-input" type="text" form="the-form" required>
<form id="the-form"></form>

<script>
"use strict";

test(() => {
const el = document.querySelector("#the-input");
const form = document.querySelector("#the-form");

let firedInvalid = false;
el.addEventListener("invalid", () => {
firedInvalid = true;
});

assert_false(form.checkValidity(), "checkValidity");
assert_false(form.reportValidity(), "reportValidity");
assert_true(firedInvalid, "fired invalid event");
});
</script>

0 comments on commit c92f9c1

Please sign in to comment.