is there any way to check if a specific field isValid instead of the whole form? #11226
Replies: 2 comments 4 replies
-
|
Would the Otherwise, there's a |
Beta Was this translation helpful? Give feedback.
-
|
For a field component, I usually prefer const { field, fieldState } = useController({
control: form.control,
name: "name",
})
const valid = fieldState.isDirty && !fieldState.error
return <Input {...field} valid={valid} />And configure the form so validation runs before submit: const form = useForm<FormType>({
resolver: zodResolver(formSchema),
mode: "onChange",
})If you want to use const { formState, getFieldState } = form
const nameState = getFieldState("name", formState)
const valid = nameState.isDirty && !nameState.errorFor the async |
Beta Was this translation helpful? Give feedback.
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'm currently facing an issue with my form, because i need to add a "valid" state to each field if ti satisfies the schema validation. however, i can only check after submitting if the form is valid:
const { formState: { isValid }} = form;the feature i need to implement is add a green border to the input if it is a valid input, before submitting the form. is it possible to verify if only a field is valid, for example, form.getValues('name').isValid?
this is my current implementation, but checking if the whole form is valid instead of the specific field:
Beta Was this translation helpful? Give feedback.
All reactions