Replies: 1 comment 1 reply
-
|
The approach I have used is to validate with onChange, but show errors based on blur or if user has attempted to submit the form. Something like: const submissionAttempted = useStore(field.form.store, state => state.submissionAttempts > 0)
// now, conditionally render any errors
{(field.state.meta.isBlurred || submissionAttempted) && (
<em>{field.state.meta.errors.join(',')}</em>
)}This way, any errors in the onChange validator will be displayed once the user either blurs the field or attempts to submit the form, and the errors are removed as soon as the field has been changed to a valid value. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I think the best UX for field validations is
onBlurfirst andonChangeonce the field has been touched.This gives the user instant feedback once the field is touched and avoids annoying messages while the first input is being typed.
With the current
onBlurandonChangevalidation methods in Tanstack Form, the only way I found to do that is by having anonChangevalidation and showing the error only if the field has theisBlurredproperty= true. The problem with that approach is that when the user clickssubmit, the errors are not shown in the field since theisBlurredis not set totrue.Therefore, it will be nice to have something like a
onChangeBlurredin the form hook to have this behaviour out of the box.Current UX
Better UX
Beta Was this translation helpful? Give feedback.
All reactions