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.

Home Page:https://just-validate.dev/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

homestar9 opened this issue · comments

commented

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!

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

commented

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