Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to programmatically trigger validation on a field in 'react-hook-form'?

I try to do it like so, but it does nothing...

import {useForm, FormContext} from 'react-hook-form';

const formMethods = useForm({mode: 'onSubmit'});
const {triggerValidation} = formMethods;
triggerValidation('myFieldName');

return (
    <FormContext {...formMethods}>
        //here are my form fields, one of which has the key of 'myFieldName'
    </FormContext>
);
like image 880
k-wasilewski Avatar asked Jan 26 '26 08:01

k-wasilewski


1 Answers

you've to use trigger method: https://react-hook-form.com/api/useform/trigger

like image 141
Joris Avatar answered Jan 28 '26 21:01

Joris