# Demo A feature demo can be found [here](https://demos.danremollino.dev/form-validation/). # Documentation Importing the `Validation` class queries the current page for `
` elements and disables the default browser [constraint validation](https://developer.mozilla.org/en-US/docs/Web/HTML/Constraint_validation) by adding a `novalidate` attribute to that element. The default behavior is to validate each field when their value is updated, and validate the entire form when it is submitted. This can be changed to only validate on form submission by setting [`onlyOnSubmit`](#onlyonsubmit) to `true` on the instance. Once a field is marked invalid, it will always re-validate when its value is changed regardless of the [`onlyOnSubmit`](#onlyOnSubmit) value. > `required` fields are first tested for blank. If this check is passed, fields are then tested based on their `type` attribute value if applicable. (Described [below](#markup).) Lastly, the field will test for a user supplied [pattern](#pattern) if present. ## Required Fields Usually, the majority of fields in a form need validation. To make setup easier, instances of the *Validation* class have a default [`reqAll`](#reqall) value of `true`. This marks all fields that meet the following criteria required and needing validation: * Have a `name` attribute. * Not [`disabled`](https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/disabled). Indivudual fields can then be excluded from validation as described [below](#reqall). This functionality can be inverted by setting [`reqAll`](#reqall) to `false`, and manually giving your required fields a [`required`](https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/required) attribute. ```html
``` `` `type` attribute values of `checkbox` and `radio` only need one option to have the `required` attribute, however, it is recommended to add it to all options for consistency. More information on checkbox and radio fields can be found [below](#checkbox-and-radio-fields). ### Required Indicator A `` tag with class of `required__indicator` containing an asterisk(*) character will be inserted [`beforeend`](https://developer.mozilla.org/en-US/docs/Web/API/Element/insertAdjacentHTML#beforeend) of a required field's `