ElementInternals: willValidate property

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.

  • constraint validation.

    Elements that are barred from being candidates for constraint validation include those that have the attributes: disabled, hidden or readonly, input elements of type=button or type=reset, or any element that is a <datalist> element or has a <datalist> element ancestor.

Value

true if the element is a candidate for constraint validation, otherwise false.

Exceptions

NotSupportedError DOMException

Thrown if the element does not have its formAssociated property set to true.

Examples

The following example shows a custom checkbox component with formAssociated set to true, the value of willValidate is logged to the console.

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

Specifications

Specification
Product help
  • ariaColCount
  • ariaCurrent
  • ariaHasPopup
  • ariaLevel
  • ariaMultiSelectable
  • ariaPressed
  • ariaRoleDescription
  • ariaRowSpan
  • ariaValueMax
  • form
  • states
  • checkValidity()
  • CustomElementRegistry
  • Element.shadowRoot
  • HTMLElement.attachInternals()
  • Node.isConnected
  • Window.customElements
  • ","source":{"folder":"en-us/web/api/elementinternals/willvalidate","github_url":"https://github.com/mdn/content/blob/main/files/en-us/web/api/elementinternals/willvalidate/index.md","last_commit_url":"https://github.com/mdn/content/commit/ce10da0e9d23d241b175d8d68bf93507734b7c48","filename":"index.md"},"summary":"The willValidate read-only property of the ElementInternals interface returns true if the element is a submittable element that is a candidate for constraint validation.","title":"ElementInternals: willValidate property","toc":[{"text":"Value","id":"value"},{"text":"Examples","id":"examples"},{"text":"Specifications","id":"specifications"},{"text":"Browser compatibility","id":"browser_compatibility"}],"baseline":{"baseline":"low","baseline_low_date":"2023-03-27","support":{"chrome":"77","chrome_android":"77","edge":"79","firefox":"98","firefox_android":"98","safari":"16.4","safari_ios":"16.4"}},"browserCompat":["api.ElementInternals.willValidate"],"pageType":"web-api-instance-property"}}

    Follow Lee on X/Twitter - Father, Husband, Serial builder creating AI, crypto, games & web tools. We are friends :) AI Will Come To Life!

    Check out: eBank.nz (Art Generator) | Netwrck.com (AI Tools) | Text-Generator.io (AI API) | BitBank.nz (Crypto AI) | ReadingTime (Kids Reading) | RewordGame | BigMultiplayerChess | WebFiddle | How.nz | Helix AI Assistant