Source code
Revision control
Copy as Markdown
Other Tools
Test Info:
- This WPT test may be referenced by the following Test IDs:
- /html/semantics/forms/constraints/using-form-attribute.html - WPT Dashboard Interop Dashboard
<!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>