New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
issue: event.stopPropagation() does not work in callback passed to handleSubmit #916
Comments
From looking at the source in So the |
hey, @c-t-k we do support async callback within the |
@bluebill1049 I think you might misunderstand me. I understand you can pass an async callback to See the codesandbox I posted above to see where this is going wrong. The const onSubmit = handleSubmit((value, ev) => {
ev?.stopPropagation();
onSubmitCallback(value);
onClose();
}); However you can see that when the modal's form is submitted, it ends up triggering the outer form despite I believe this is because react invokes an |
Yes, @c-t-k I understand that, what's your prospered change, I don't think we can remove the await for the onSubmit=((e) => {
// e.
handleSubmit(() => {})(e)
}) |
@bluebill1049 yeah, this is the workaround I've been using: <form onSubmit={((e) => {
e.stopPropagation();
form.handleSubmit(onSubmitCallback)(e)
})} /> I don't have a proposed fix, it seems to be a problem w/ the design of |
https://react-hook-form.com/api/useform/handlesubmit/ Would you like to send us a PR on this? We can describe and move it under the rules section. |
@c-t-k Could you try this - { ev.stopPropagation(); handleSubmit(onSubmit)}} className="outer-form"> |
Any progress on this? Might be nice to be able to have a property in |
Hi All, i was working on this issue, this approach is working: if we remove the form from child or simple apply event handler on button itself. const onSubmit = handleSubmit((value, ev) => { please let me know if you need more clarity. Thanks CC - @c-t-k |
@c-t-k could you please assign this to me. |
Can someone assign this to me, if it is not resolved |
This is similar to the other answers but I'll post my solution here:
|
Version Number
7.43.2
Codesandbox/Expo snack
https://codesandbox.io/s/snowy-https-hnyckh?file=/src/App.tsx
Steps to reproduce
Expected behaviour
The outer form should not be submitted as the
Modal
component callsevent.stopPropagation()
in the callback passed tohandleSubmit
.What browsers are you seeing the problem on?
Chrome
Relevant log output
Code of Conduct
The text was updated successfully, but these errors were encountered: