Open stuffmattdoes opened 3 months ago
I've also noticed that the submit button/element does not appear in formData object on submission events. If a button is used to submit a form and also includes a name/value pair, it should be in FormData.
Example
// JS
document
.querySelector("form")
.addEventListener("submit", (event) => {
let formData = new FormData(event.currentTarget);
formData.get('FirstButton') // should be reference to <button/> but is undefined
});
// HTML
<form>
<button name='FirstButton' value='FirstValue'>First</button> // Click
<button name='SecondButton' value='SecondValue'>Second</button>
</form>
I think this is a good feature request. I think that the submit()
function could be updated to accept an optional submitter
param, and also be updated to conditionally use form.requestSubmit(submitter)
if it is available?
Regarding the request about FormData
, the submitter is the second arg to new FormData(form, submitter)
so when creating a FormData
, you can add the submitter.
However, I think maybe the formValues()
helper could also be updated to accept an optional submitter
param so that param can be passed to the new FormData()
construction that happens in formValues()
When I submit a
<form/>
, I'd like to know which element submitted the form. In native HTML, I have access to the element that submitted the form via event.submitterRead more about the event.submitter spec here
Example:
Expected: event.submitter should be a reference to the DOM node
Received: event.submitter is null