I use react-hook-form, yup validation.
If I finish the form, before I try to submit, the code automatically submits the form.
But I should prevent this before the user touches the submit button.
Any idea for the auto submission?
const Parent = () => {
const schema = Yup.object().shape({
.....
});
const methods = useForm({
defaultValues: {...},
resolver: yupResolver(schema),
mode: 'all',
});
....
}
And here is the child form
const Form = () => {
const {handleSubmit, formState } = useFormContext();
const onFinish = async (data: {[key: string]: any}) => {
// submit
}
return (
<form onSubmit={handleSubmit(onFinish)}>
....
</form>
)
}