-
Notifications
You must be signed in to change notification settings - Fork 49.7k
Description
When creating a form, with multiple submit buttons, you can tell which button is the submitter by giving the button a name and value. But if you include an input element with the name id within the form, like <input type="hidden" name="id" value="1" /> this information is gone.
The issue seems to originate from the function createFormDataWithSubmitter() in React. Specifically where it checks for form.id.
react/packages/react-dom-bindings/src/events/plugins/FormActionEventPlugin.js
Lines 63 to 65 in 71b3a03
| if (form.id) { | |
| temp.setAttribute('form', form.id); | |
| } |
When you include an input element with the name id, form.id will be the actual input element. I guess the intention here is instead to get the id attribute on the form instead?
<form id="my-form">
<input type="hidden" name="id" value="1" />
</form>In the above example, form.id will be the <input /> element, not my-form. If I remove the input element, form.id will be my-form.
React version: 19.2
Steps To Reproduce
- Create a form with with a named submit button (e.g.
action, and an input field with nameid - Call
formData.get('action')within theactionhandler of the form
Link to code example: https://codesandbox.io/p/sandbox/naughty-dew-d39gvp?file=%2Fsrc%2FApp.js%3A16%2C16
The current behavior
The return value of formData.get('action') is null
The expected behavior
The return value should be the value of the submitter.