-
Notifications
You must be signed in to change notification settings - Fork 49.9k
Description
When a form action is triggered by a button that is outside the form's tag the button's name and value is missing from the form data provided to the action. When the button submitting the form is inside the form tag the button's form data is properly surfaced to the action:
React version: 0.0.0-experimental-2807d781a-20230918
Steps To Reproduce
- Create a form that calls an action when submitted with a button outside the form tag submits the form. The button that submits the form should have the
nameandvalueattributes set with non-null values. The action should take aformDataargument and log the button's value:function Component() { function action(formData) { console.log(formData.get("n1")); } return ( <> <button type="submit" name="n1" value="v1" form="form-id"> Submit </button> <form action={action} id="form-id"></form> </> ); } - Click the button that submits the form
Link to code example: https://codesandbox.io/s/flamboyant-meadow-gcvpx9?file=/App.js
The current behavior
The formData provided to the form action doesn't contain the key-value pair information of the button that submitted the form when the button is outside the form's tag. This means that nothing is logged because the n1 key doesn't exist in formData
The expected behavior
The value of the external button to be logged (v1 in the example above) because formData includes the
