T
TanStack9mo ago
foreign-sapphire

Validate single field when change happend

Hello everyone! I have a problem with next case: I have form with couple of fields, also I have my validation schema written using yup. That schema validates whole form, but I want to validate single field when user types anything there. Currently it looks like this
<form.Field
name={item.name as keyof FormSchema}
key={index}
listeners={{
onChange: onChange
}}
validatorAdapter={yupValidator()}
validators={{
onChange: validationSchema,
}}
>
<form.Field
name={item.name as keyof FormSchema}
key={index}
listeners={{
onChange: onChange
}}
validatorAdapter={yupValidator()}
validators={{
onChange: validationSchema,
}}
>
Validation doesn't work beacouse validationSchema provides validation for whole form. How can I solve this?
2 Replies
eager-peach
eager-peach9mo ago
Not a yup user but looks like pick should work to get a single Field https://github.com/jquense/yup?tab=readme-ov-file#objectpickkeys-string-schema
GitHub
GitHub - jquense/yup: Dead simple Object schema validation
Dead simple Object schema validation. Contribute to jquense/yup development by creating an account on GitHub.
foreign-sapphire
foreign-sapphireOP9mo ago
thank you

Did you find this page helpful?