-
Notifications
You must be signed in to change notification settings - Fork 22.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
281 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
--- | ||
title: "HTMLButtonElement: validity property" | ||
short-title: validity | ||
slug: Web/API/HTMLButtonElement/validity | ||
page-type: web-api-instance-property | ||
browser-compat: api.HTMLButtonElement.validity | ||
--- | ||
|
||
{{APIRef("HTML DOM")}} | ||
|
||
The **`validity`** read-only property of the {{domxref("HTMLButtonElement")}} interface returns a {{domxref("ValidityState")}} with the validity states that this element is in. | ||
|
||
## Value | ||
|
||
A {{domxref("ValidityState")}} object. | ||
|
||
## Examples | ||
|
||
The following example gets the validity state of a button element and processes it if it is not valid: | ||
|
||
```js | ||
const button = document.getElementById("myButton"); | ||
if (!button.validity.valid) { | ||
// Test each validity state | ||
} | ||
``` | ||
|
||
## Specifications | ||
|
||
{{Specifications}} | ||
|
||
## Browser compatibility | ||
|
||
{{Compat}} | ||
|
||
## See also | ||
|
||
- {{domxref("HTMLButtonElement.checkValidity()")}} | ||
- {{HTMLElement("button")}} | ||
- {{HTMLElement("form")}} | ||
- [Learn: Client-side form validation](/en-US/docs/Learn/Forms/Form_validation) | ||
- [Guide: Constraint validation](/en-US/docs/Web/HTML/Constraint_validation) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
--- | ||
title: "HTMLFieldSetElement: validity property" | ||
short-title: validity | ||
slug: Web/API/HTMLFieldSetElement/validity | ||
page-type: web-api-instance-property | ||
browser-compat: api.HTMLFieldSetElement.validity | ||
--- | ||
|
||
{{APIRef("HTML DOM")}} | ||
|
||
The **`validity`** read-only property of the {{domxref("HTMLFieldSetElement")}} interface returns a {{domxref("ValidityState")}} with the validity states that this element is in. Although {{HTMLElement("fieldset")}} elements are never candidates for [constraint validation](/en-US/docs/Web/HTML/Constraint_validation), the validity state may still be invalid if a custom validity message has been set. | ||
|
||
> [!NOTE] | ||
> The {{cssxref(":valid")}} and {{cssxref(":invalid")}} CSS pseudo-classes are applied to `<fieldset>` elements based on the validity of its descendant form controls, not the fieldset itself. | ||
## Value | ||
|
||
A {{domxref("ValidityState")}} object. | ||
|
||
## Examples | ||
|
||
The following example shows how you can have a `<fieldset>` in an invalid state, even when {{domxref("HTMLFieldSetElement/checkValidity", "checkValidity()")}} returns `true`. | ||
|
||
```js | ||
const fieldSet = document.getElementById("myFieldSet"); | ||
fieldSet.setCustomValidity("This fieldset is invalid."); | ||
console.log(fieldSet.validity.valid); // false | ||
console.log(fieldSet.validity.checkValidity()); // true | ||
``` | ||
|
||
## Specifications | ||
|
||
{{Specifications}} | ||
|
||
## Browser compatibility | ||
|
||
{{Compat}} | ||
|
||
## See also | ||
|
||
- {{domxref("HTMLFieldSetElement.checkValidity()")}} | ||
- {{HTMLElement("fieldset")}} | ||
- {{HTMLElement("form")}} | ||
- [Learn: Client-side form validation](/en-US/docs/Learn/Forms/Form_validation) | ||
- [Guide: Constraint validation](/en-US/docs/Web/HTML/Constraint_validation) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
--- | ||
title: "HTMLInputElement: validity property" | ||
short-title: validity | ||
slug: Web/API/HTMLInputElement/validity | ||
page-type: web-api-instance-property | ||
browser-compat: api.HTMLInputElement.validity | ||
--- | ||
|
||
{{APIRef("HTML DOM")}} | ||
|
||
The **`validity`** read-only property of the {{domxref("HTMLInputElement")}} interface returns a {{domxref("ValidityState")}} with the validity states that this element is in. | ||
|
||
## Value | ||
|
||
A {{domxref("ValidityState")}} object. | ||
|
||
## Examples | ||
|
||
The following example gets the validity state of an input element and processes it if it is not valid: | ||
|
||
```js | ||
const input = document.getElementById("myInput"); | ||
if (!input.validity.valid) { | ||
// Test each validity state | ||
} | ||
``` | ||
|
||
## Specifications | ||
|
||
{{Specifications}} | ||
|
||
## Browser compatibility | ||
|
||
{{Compat}} | ||
|
||
## See also | ||
|
||
- {{domxref("HTMLInputElement.checkValidity()")}} | ||
- {{HTMLElement("input")}} | ||
- {{HTMLElement("form")}} | ||
- [Learn: Client-side form validation](/en-US/docs/Learn/Forms/Form_validation) | ||
- [Guide: Constraint validation](/en-US/docs/Web/HTML/Constraint_validation) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
--- | ||
title: "HTMLOutputElement: validity property" | ||
short-title: validity | ||
slug: Web/API/HTMLOutputElement/validity | ||
page-type: web-api-instance-property | ||
browser-compat: api.HTMLOutputElement.validity | ||
--- | ||
|
||
{{APIRef("HTML DOM")}} | ||
|
||
The **`validity`** read-only property of the {{domxref("HTMLOutputElement")}} interface returns a {{domxref("ValidityState")}} with the validity states that this element is in. Although {{HTMLElement("output")}} elements are never candidates for [constraint validation](/en-US/docs/Web/HTML/Constraint_validation), the validity state may still be invalid if a custom validity message has been set. | ||
|
||
## Value | ||
|
||
A {{domxref("ValidityState")}} object. | ||
|
||
## Examples | ||
|
||
The following example shows how you can have a `<output>` in an invalid state, even when {{domxref("HTMLOutputElement/checkValidity", "checkValidity()")}} returns `true`. | ||
|
||
```js | ||
const output = document.getElementById("myOutput"); | ||
output.setCustomValidity("This output is invalid."); | ||
console.log(output.validity.valid); // false | ||
console.log(output.validity.checkValidity()); // true | ||
``` | ||
|
||
## Specifications | ||
|
||
{{Specifications}} | ||
|
||
## Browser compatibility | ||
|
||
{{Compat}} | ||
|
||
## See also | ||
|
||
- {{domxref("HTMLOutputElement.checkValidity()")}} | ||
- {{HTMLElement("output")}} | ||
- {{HTMLElement("form")}} | ||
- [Learn: Client-side form validation](/en-US/docs/Learn/Forms/Form_validation) | ||
- [Guide: Constraint validation](/en-US/docs/Web/HTML/Constraint_validation) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
--- | ||
title: "HTMLSelectElement: validity property" | ||
short-title: validity | ||
slug: Web/API/HTMLSelectElement/validity | ||
page-type: web-api-instance-property | ||
browser-compat: api.HTMLSelectElement.validity | ||
--- | ||
|
||
{{APIRef("HTML DOM")}} | ||
|
||
The **`validity`** read-only property of the {{domxref("HTMLSelectElement")}} interface returns a {{domxref("ValidityState")}} with the validity states that this element is in. | ||
|
||
## Value | ||
|
||
A {{domxref("ValidityState")}} object. | ||
|
||
## Example | ||
|
||
The following example gets the validity state of a select element and processes it if it is not valid: | ||
|
||
```js | ||
const select = document.getElementById("mySelect"); | ||
if (!select.validity.valid) { | ||
// Test each validity state | ||
} | ||
``` | ||
|
||
## Specifications | ||
|
||
{{Specifications}} | ||
|
||
## Browser compatibility | ||
|
||
{{Compat}} | ||
|
||
## See also | ||
|
||
- {{domxref("HTMLSelectElement.checkValidity()")}} | ||
- {{HTMLElement("select")}} | ||
- {{HTMLElement("form")}} | ||
- [Learn: Client-side form validation](/en-US/docs/Learn/Forms/Form_validation) | ||
- [Guide: Constraint validation](/en-US/docs/Web/HTML/Constraint_validation) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
--- | ||
title: "HTMLTextAreaElement: validity property" | ||
short-title: validity | ||
slug: Web/API/HTMLTextAreaElement/validity | ||
page-type: web-api-instance-property | ||
browser-compat: api.HTMLTextAreaElement.validity | ||
--- | ||
|
||
{{APIRef("HTML DOM")}} | ||
|
||
The **`validity`** read-only property of the {{domxref("HTMLTextAreaElement")}} interface returns a {{domxref("ValidityState")}} with the validity states that this element is in. | ||
|
||
## Value | ||
|
||
A {{domxref("ValidityState")}} object. | ||
|
||
## Examples | ||
|
||
The following example gets the validity state of a text area element and processes it if it is not valid: | ||
|
||
```js | ||
const textArea = document.getElementById("myTextArea"); | ||
if (!textArea.validity.valid) { | ||
// Test each validity state | ||
} | ||
``` | ||
|
||
## Specifications | ||
|
||
{{Specifications}} | ||
|
||
## Browser compatibility | ||
|
||
{{Compat}} | ||
|
||
## See also | ||
|
||
- {{domxref("HTMLTextAreaElement.checkValidity()")}} | ||
- {{HTMLElement("textarea")}} | ||
- {{HTMLElement("form")}} | ||
- [Learn: Client-side form validation](/en-US/docs/Learn/Forms/Form_validation) | ||
- [Guide: Constraint validation](/en-US/docs/Web/HTML/Constraint_validation) |