cferdinandi / validate

A lightweight form validation script.
MIT License
230 stars 39 forks source link

Change checkboxes and radios to validate on click #29

Closed robinwhittleton closed 7 years ago

robinwhittleton commented 7 years ago

This library has made the choice to validate inputs on blur; this is a totally reasonable choice for normal text inputs as it stops potential off-putting switching between validity states as the user types. For radios and checkboxes though there’s no typing to be done, yet the library still waits for a blur event (i.e. a click somewhere else or a tab away) before updating the visual validity state.

This commit adds a click event handler for radios and checkboxes that will evaluate the validity immediately after the browser changes the internal state of the control. This provides immediate feedback to the user that they’ve corrected the problem.

Example without this change (this is particularly bad as it’s using a custom form control that is basing its styling on validate’s state): A screen capture of the behaviour without this patch

Example with this change: A screen capture of the behaviour with this patch

cferdinandi commented 7 years ago

Good call. Definitely the way to go. Thanks!