Correct validation/error display on both field and form components
I'm curious what everyone's using. I love tanstack form but I feel it's difficult to achieve good defaults on the form and field validation - using zod v4 for useAppForm.validators.
What I have right now:
This is mostly OK -- but the error is too eager (when user starts typing an email in a field, it will show the error until the put
@.com
, and the submit button shows as valid when the form is first loaded without anything is typed, then gets invalidated as user types.
I'd like to achieve a configuration that:
1. Displays errors on a field only if it's dirty AND user is no longer on it
2. Submit button should be invalid on first load3 Replies
environmental-rose•3mo ago
if you attach the onBlur event handler
field.handleBlur
, you can utilize the meta.isBlurred
property to display errors
as for the submit button, give isPristine
a try. It‘s true until a user changes a field
@winston.pgenetic-orangeOP•3mo ago
ah isPristine works. How do I attach the isBlurred? If I do a plain isBlurred as one of the && conditions, it doesn't show any error
even after user leaves the field
environmental-rose•3mo ago
your UI component should have some form of
onBlur={() => {}}
pass field.handleBlur
in there