Nested forms #7038
Replies: 5 comments 7 replies
-
in react hook form, you probably want to build multiple forms. so you can have a main form and update the main form with sub form values. |
Beta Was this translation helpful? Give feedback.
-
Just use in the form To call |
Beta Was this translation helpful? Give feedback.
-
You should definitely look into the portals. Nested form is not a valid HTML structure – this can impact both UX and SEO. |
Beta Was this translation helpful? Give feedback.
-
Okay finally figured out the answer to this, this issue has been haunting me for way too long: <form
onSubmit={form.handleSubmit(onSubmit)}
id="unit-skill-dialog"
> <Button type="submit" form="unit-skill-dialog">
Submit
</Button> Add the id and form attributes to the |
Beta Was this translation helpful? Give feedback.
-
The easiest way I've seen to get this working (as none of the tricks about Advantages are not having to worry about form IDs (which did not work in my app - I don't know why), not having to worry about invalid form nesting, not having to worry about which form events to call or not. Doing it this way, I can have separate sub forms each handled by RHF with different sub-schemas as re-usable pieces I can use throughout my app, but they communicate a small set of values up to their parent form with a callback that is called whenever the subform is done with its successful submission. Something like this:
|
Beta Was this translation helpful? Give feedback.
-
Hey all, what is best practice when this kind of ux is given: Nedted form example. HTML 5 forbid form nesting:https://stackoverflow.com/questions/379610/can-you-nest-html-forms. though seems like there are hacks around it even with react hook form:Nested form in React hook form. What would be the right way to do it?
Beta Was this translation helpful? Give feedback.
All reactions