Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Form submission element is absent from event.submitter #55

Open
stuffmattdoes opened this issue May 22, 2024 · 3 comments
Open

Form submission element is absent from event.submitter #55

stuffmattdoes opened this issue May 22, 2024 · 3 comments

Comments

@stuffmattdoes
Copy link

stuffmattdoes commented May 22, 2024

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.submitter

Read more about the event.submitter spec here

Example:

// JS
document
    .querySelector("form")
    .addEventListener("submit", (event) => {
        let submitter = event.submitter;
    });

// HTML
<form>
    <button name='FirstButton' value='FirstValue'>First</button>
    <button name='SecondButton' value='SecondValue'>Second</button>
</form>

Expected:
event.submitter should be a reference to the DOM node

Received:
event.submitter is null

@stuffmattdoes
Copy link
Author

stuffmattdoes commented May 22, 2024

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.

Read more here

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>

@michaelwarren1106
Copy link
Collaborator

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()

@anyuruf
Copy link

anyuruf commented Sep 24, 2024

I think the names should be similar for the buttons only their values different. check https://www.youtube.com/watch?v=w2i-9cYxSdc&pp=ygUZUmVtaXgganMgc2luZ2xlIG11bHRpZm9ybQ%3D%3D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants