DOM Methods
ElementInternals.reportValidity()
Checks constraints and asks the browser to report a validation problem if invalid and the invalid event is not canceled. Actual UI depends on the browser. Only supported for form-associated custom elements. Example result: false.
Formal Syntax & Structure
html syntaxhtml
internals.reportValidity()Return Value
boolean
True when valid or not a validation candidate.
Working Example
Example Snippethtml
<form id="demo-form"> <demo-field name="city"></demo-field></form><p> Result: <output id="result"></output></p><script> const result = document.getElementById("result"); (async () => { class DemoField extends HTMLElement { static formAssociated = true; constructor() { super(); this.internals = this.attachInternals(); } } customElements.define("demo-field", DemoField); const field = document.querySelector("demo-field"); const internals = field.internals; internals.setValidity({customError:true}, "Invalid"); result.textContent = internals.reportValidity(); })().catch(error => { result.textContent = "Error: " + error.name; });</script>