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.
|
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 name id
- Call
formData.get('action') within the action handler 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.
When creating a form, with multiple submit buttons, you can tell which button is the submitter by giving the button a
nameandvalue. But if you include an input element with the nameidwithin 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 forform.id.react/packages/react-dom-bindings/src/events/plugins/FormActionEventPlugin.js
Lines 63 to 65 in 71b3a03
When you include an input element with the name
id,form.idwill be the actual input element. I guess the intention here is instead to get theidattribute on the form instead?In the above example,
form.idwill be the<input />element, notmy-form. If I remove the input element,form.idwill bemy-form.React version: 19.2
Steps To Reproduce
action, and an input field with nameidformData.get('action')within theactionhandler of the formLink 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')isnullThe expected behavior
The return value should be the
valueof the submitter.