How to validate fields individually on change and not the entire form, but the validator will be set at the form level #1612
-
In React Hook Form, Due to constraints, I have to set the validators at the form level in Tanstack Form. However, it's a bad user experience when the user is interacting with a field, then other fields suddenly turn red. const form = useForm({
defaultValues: {
name: "",
email: "",
password: "",
confirmPassword: "",
} as SignupForm,
validators: {
onChange: formSchema, // validate fields individually
},
onSubmit: ({ value }) => {
alert(JSON.stringify(value, null, 2));
},
}); |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 7 replies
-
Answered on the Discord, but to reiterate here: Utilize the field meta state to prevent untouched fields from showing errors. |
Beta Was this translation helpful? Give feedback.
-
I really don't want to be manually setting validators for each field every time for every form. This was super easy with React Hook Form; If Tanstack Form could support an extra field, maybe called Maybe it's because I'm coming from React Hook Form, but that individual validation really helps to compose my forms better. |
Beta Was this translation helpful? Give feedback.
-
I think I found a similar issue #1272. I also found a PR for this feature that was closed: #1286. @Balastrong I really wish you had approved that PR. As you can see, this is a common feature request from those coming from React Hook Form. |
Beta Was this translation helpful? Give feedback.
I Just checked the React Hook Form docs. I'm actually requesting for the
mode
not therevalidateMode
: