I need to submit the form with react hook form with zod validation. But in my condition, the submit button was outside of the form tag. So I used the id form method. ( please sudjust any other method as well. )
<form onSubmit={methods.handleSubmit(onSubmit)} id="sequenceForm">
<label htmlFor="startDate">Start Date</label>
<DatePickers name="startDate" id="startDate" />
</form>
<button
form="sequenceForm"
onClick={() => {
setDialogOpen(false);
}}
>
Save
</button>
>! not working
<Button
form="sequenceForm"
onClick={() => {
setDialogOpen(false);
}}
>
Save
</Button>
I need to use MUI button with form props as like as button field.
2
Answers
submit with requestSubmit works for me.
you could have the button call your own form submit function. for example:
i’m not 100% sure that is how you submit the form using a ref, but hopefully the idea itself is helpful.