Baseline 2023
Newly available
The validity
read-only property of the ElementInternals
interface returns a ValidityState
object which represents the different validity states the element can be in, with respect to constraint validation.
A ValidityState
object.
NotSupportedError
DOMException
Thrown if the element does not have its formAssociated
property set to true
.
The following example shows a custom checkbox component with formAssociated
set to true
, the value of validity.valid
is logged to the console.
class CustomCheckbox extends HTMLElement {
static formAssociated = true;
constructor() {
super();
this.internals_ = this.attachInternals();
}
// â¦
}
window.customElements.define("custom-checkbox", CustomCheckbox);
let element = document.getElementById("custom-checkbox");
console.log(element.internals_.validity.valid);
Specifications Browser compatibility
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.3