ElementInternals: willValidate プロパティ

Baseline 2023
Newly available

Since March 2023, this feature works across the latest devices and browser versions. This feature might not work in older devices or browsers.

willValidateElementInternals インターフェイスの読み取り専用プロパティで、この要素が制約検証の候補である送信可能要素である場合に true を返します。

制約検証の候補から除外される要素には、disabledhiddenreadonlyの属性を持つ要素、type=buttontype=reset の入力要素、<datalist> 要素や <datalist> 要素の祖先を持つ要素などがあります。

要素が制約検証の候補であれば true、そうでなければ false です。

例外

NotSupportedError DOMException

要素の formAssociated プロパティが true に設定されていない場合に発生します。

次の例は formAssociatedtrue に設定されたカスタムチェックボックスコンポーネントを表示させており、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

ブラウザーの互換性

Report problems with this compatibility data on GitHub
desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
willValidate

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support