mirror of
https://github.com/jquery-validation/jquery-validation.git
synced 2025-12-14 20:35:47 +01:00
Add Accessibility section to Readme (#2149)
* Add accessibility section to readme - speaks to errorElement * Add link to errorElement in doc Co-authored-by: Joe Watkins <info@joe-watkins.io>
This commit is contained in:
21
README.md
21
README.md
@@ -73,6 +73,27 @@ $("#myForm").validate({
|
||||
});
|
||||
```
|
||||
|
||||
## Accessibility
|
||||
For an invalid field, the default output for the jQuery Validation Plugin is an error message in a `<label>` element. This results in two `<label>` elements pointing to a single input field using the `for` attribute. While this is valid HTML, it has inconsistent support across screen readers.
|
||||
|
||||
For greater screen reader support in your form's validation, use the `errorElement` parameter in the `validate()` method. This option outputs the error in an element of your choice and automatically adds ARIA attributes to the HTML that help with screen reader support.
|
||||
|
||||
`aria-describedby` is added to the input field and it is programmatically tied to the error element chosen in the `errorElement` parameter.
|
||||
|
||||
``` js
|
||||
$("#myform").validate({
|
||||
errorElement: "span"
|
||||
});
|
||||
```
|
||||
|
||||
``` html
|
||||
<label for="name">Name</label>
|
||||
<input id="name" aria-describedby="unique-id-here">
|
||||
<span class="error" id="unique-id-here">This field is required</span>
|
||||
```
|
||||
|
||||
[Learn more about errorElement](https://jqueryvalidation.org/validate/#errorelement)
|
||||
|
||||
## License
|
||||
Copyright © Jörn Zaefferer<br>
|
||||
Licensed under the MIT license.
|
||||
|
||||
Reference in New Issue
Block a user