You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
HTML form submissions that are triggered from a button click do not pass the clicked button as the event.submitter in the SubmitEvent event. Forms with an onSubmit handler are unable to identify the element that triggered the SubmitEvent. The clicked button, if it has a name, will also be submitted in the GET/POST.
One dev pattern in the remix framework is to use a <button type="submit" name="_action" /> to signal to the POST handler which button was clicked (and branch to take action accordingly). This bug causes problems when using testing-library to write unittests for remix applications that rely on this pattern, as the _action isn't submitted with the POST.
Normal browser behavior for button clicks is to supply the button as the event.submitter. This allows event handlers to identify the element that triggered the event event.target. Additionally if the button has a name, it is included in formData.
Clicking the button should emit the button in the console.log.
Remix, a react-based web application that uses leverages browser-standard capabilities like html form submissions, uses this technique to have a single endpoint that can perform multiple tasks. This was also a typical pattern back before single page apps took over.
I see the happy-dom HTMLFormElement code supports supply a submitter, but neither HTMLButtonElement nor HTMLInputElement(type="submit") pass this along to it. I'll be submitting a PR to fix this.
Screenshots
A normal form submission clicked by a button sets the event.submitter to be the button:
Device:
n/a
The text was updated successfully, but these errors were encountered:
Describe the bug
HTML form submissions that are triggered from a button click do not pass the clicked button as the event.submitter in the
SubmitEvent
event. Forms with anonSubmit
handler are unable to identify the element that triggered theSubmitEvent
. The clicked button, if it has a name, will also be submitted in the GET/POST.One dev pattern in the remix framework is to use a
<button type="submit" name="_action" />
to signal to the POST handler which button was clicked (and branch to take action accordingly). This bug causes problems when using testing-library to write unittests for remix applications that rely on this pattern, as the _action isn't submitted with the POST.To Reproduce
Steps to reproduce the behavior:
Expected behavior
See the Mozilla Developer Network reference for the
SubmitEvent.submitter
propertyNormal browser behavior for button clicks is to supply the button as the
event.submitter
. This allows event handlers to identify the element that triggered the eventevent.target
. Additionally if the button has a name, it is included in formData.For dom like (in react):
Clicking the button should emit the button in the console.log.
Remix, a react-based web application that uses leverages browser-standard capabilities like html form submissions, uses this technique to have a single endpoint that can perform multiple tasks. This was also a typical pattern back before single page apps took over.
I see the happy-dom HTMLFormElement code supports supply a submitter, but neither HTMLButtonElement nor HTMLInputElement(type="submit") pass
this
along to it. I'll be submitting a PR to fix this.Screenshots
A normal form submission clicked by a button sets the event.submitter to be the button:
Device:
n/a
The text was updated successfully, but these errors were encountered: