-
Hello, I have a form where I have 2 buttons : one to submit the current form and another to open a In this The weird behavior is when I submit form inside
Is there a solution for that? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 6 replies
-
This is correct you should not nest your form inside of each other. You can have several forms on a page but they should not be nested.
|
Beta Was this translation helpful? Give feedback.
-
thanks @adamayres if you want to post another comment and we can mark #3704 (reply in thread) as answer |
Beta Was this translation helpful? Give feedback.
-
Reposting as a top level comment, originally posted here. I ran into this same issue and have created a codesandox with the reproduction here: https://codesandbox.io/s/react-hook-form-nested-9qtck Some things to note
Workaround In the nested form in the modal, change this: <Form onSubmit={handleSubmit(onValid, onInvalid)}> To this: <Form
onSubmit={(event) => {
event.stopPropagation();
handleSubmit(onValid, onInvalid)(event)
}}
> Potential Fix in library In |
Beta Was this translation helpful? Give feedback.
Reposting as a top level comment, originally posted here.
I ran into this same issue and have created a codesandox with the reproduction here: https://codesandbox.io/s/react-hook-form-nested-9qtck
Some things to note
<body>
element, so it is not a nested form with regards to the DOM. The modal, and the form it contains, are however child components of the containing form, so as far as the React tree is concerned, they are nested. The modal and it's form are added to the<body>
by way of using a React Portal, here is a reference to the code where that is done.