horprogs / Just-validate

Modern, simple, lightweight (~5kb gzip) form validation library written in Typescript, with no dependencies (no JQuery!). Support a wide range of predefined rules, async, files, dates validation, custom error messages and styles, localization. Support writing custom rules and plugins.
https://just-validate.dev/
Other
511 stars 92 forks source link

Question: Is there a way to validate individual fields `onChange` or `onBlur`? #108

Closed homestar9 closed 1 year ago

homestar9 commented 1 year ago

I'm just getting started with Just-Validate, so please forgive this "noob" question, but is there a way to validate an individual field after the value changes or when a field loses focus?

For example, let's say you have an email input field. After the user types in a bad value and clicks off of the field, Is there a way to validate just that field to give the user instant feedback?

I have found that this type of user experience can be beneficial on longer forms so users can correct mistakes as they go rather than having to go back to the beginning. Thanks!

horprogs commented 1 year ago

onBlur we don't have yet, unfortunately. But there is onValidate callback where you could check the state of your fields. Together with validateBeforeSubmitting config flag user could input something and get immediate feedback, without clicking on Submit button.

https://codesandbox.io/s/just-validate-template-forked-k30wc5?file=/index.html

image
homestar9 commented 1 year ago

Thank you. I will play around with it and post back if I come up with an easy to implement workaround.