Foundation
Form
This foundation validates HTML forms and maps the results to MICL's specific error styling. It builds on the browser's native Constraint Validation API rather than replacing it: the standard attributes keep working exactly as they do without MICL, and this foundation adds component-aware error presentation and count rules for a set of related checkboxes.
- Native validation messages
- Checkbox count rules
- You decide when
Validate a form
Call miclForm.validateForm(form, true) from a submit handler. Text fields with supporting text show the browser's message in place; other controls get the native bubble. novalidate lets the submit event reach your handler.
Required fields and a required checkbox
Checkbox count rules
Describe a rule such as “two or three of these” with data-miclvalidate-* attributes on the <fieldset>. The message is shown on the first checkbox of the set.
Validate a fieldset
miclForm.validateFieldSet(fieldset, true) checks one step of a multi-step form on its own.
Silent validation
Leave out doReport to apply the error styling without moving focus or showing a bubble, for example while the user types.
Validated on every keystroke
Loading the foundation
The form foundation is not part of micl.js. Import it from dist/foundations/form, or load dist/foundations/form/index.js with a <script> tag to get the miclForm global. This page loads it the same way, after micl.js. See the Form README for the full API.