ElementInternals: willValidate プロパティ
Baseline
Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since 2023年3月.
willValidate は ElementInternals インターフェイスの読み取り専用プロパティで、この要素が制約検証の候補である送信可能要素である場合に true を返します。
制約検証の候補から除外される要素には、disabled、hidden、readonlyの属性を持つ要素、type=button や type=reset の入力要素、<datalist> 要素や <datalist> 要素の祖先を持つ要素などがあります。
値
要素が制約検証の候補であれば true、そうでなければ false です。
例外
NotSupportedErrorDOMException-
要素の
formAssociatedプロパティがtrueに設定されていない場合に発生します。
例
次の例は formAssociated が true に設定されたカスタムチェックボックスコンポーネントを表示させており、willValidate の値はコンソールにログ出力されます。
js
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_.willValidate); // true
仕様書
| Specification |
|---|
| HTML> # dom-elementinternals-willvalidate> |
ブラウザーの互換性
Loading…