Add shouldTouch
to trigger
options?
#9830
-
I was trying to implement trigger(undefined, { shouldTouch: true }); And another case for My possible use cases for this settings include:
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
i believe you can do that with setValue
|
Beta Was this translation helpful? Give feedback.
-
@SPodjasek I am in the same situation as you. I only show field errors if they have already touched the input. I use the I made this wrapper around import {FieldValues, UseFormReturn, Path} from 'react-hook-form';
export async function triggerForm<T extends FieldValues>(
form: UseFormReturn<T>,
): Promise<boolean> {
for (const [key, value] of Object.entries(form.getValues())) {
const name = key as Path<T>;
form.setValue(name, value ?? '', {
shouldTouch: true,
});
}
return form.trigger();
} Usage:const form = useForm(...);
triggerForm(form); |
Beta Was this translation helpful? Give feedback.
i believe you can do that with setValue
setValue('name', 'data', options)