-
Hey, I have a form with quite some fields. One of them is too complex so I want to place it inside a modal. On the submit of this second form, if everything is fine, I close the dialog and pass the value to the parent form. Technically, they are not parent and child, because react-bootstrap puts the modal in the of the content, near The problem is: once we submit the modal form, it triggers the onSubmit for both. I don't know if the form is triggered by RHF or by hmtl's native behaviour Maybe related to #8889 . |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 1 reply
-
Yea, #8889 is the same question. Haven't had the time to answer yet |
Beta Was this translation helpful? Give feedback.
-
Hey @Falci I think this is happening because you placed your Modal component inside parent form tag so when submit event is triggered in modal component , as it is inside other form tag submit event event spawns on that form too, so it is bubbling up to its parent form so that's causing the parent form to trigger onform submit function. |
Beta Was this translation helpful? Give feedback.
-
UI library "react-bootstrap in the example uses React Portal to show modal form by appending the modal to the default container "document.body". According to React Portal documentation (https://reactjs.org/docs/portals.html#event-bubbling-through-portals):
Add event stop propagation for onSubmit of modal form or moving modal form outside root form will solve the issue. Moving modal form: https://codesandbox.io/s/react-hook-form-example-forked-nznlzm?file=/src/index.js |
Beta Was this translation helpful? Give feedback.
@Falci @Moshyfawn @chetvishal
UI library "react-bootstrap in the example uses React Portal to show modal form by appending the modal to the default container "document.body".
According to React Portal documentation (https://reactjs.org/docs/portals.html#event-bubbling-through-portals):