-
Notifications
You must be signed in to change notification settings - Fork 47k
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
Bug: Incorrect form data when using an image submit button #29018
Comments
A minor wrinkle in just using the submitter parameter comes on the testing side; jest-environment-jsdom still wants |
This brings: - jest* up from 29.4.2 -> 29.7.0 - jsdom up from 20.0.0 -> 22.1.0 While the latest version of jest-dom-environment still wants `jsdom@^20.0.0`, it can safely use at least up to `jsdom@22.1.0`. See jestjs/jest#13825 (comment) for details. Upgrading to latest versions lets us improve some WheelEvent tests and will make it possible to test a much simpler FormData construction approach (see facebook#29018)
## Summary This brings: - jest* up from 29.4.2 -> 29.7.0 - jsdom up from 20.0.0 -> 22.1.0 While the latest version of jest-dom-environment still wants `jsdom@^20.0.0`, it can safely use at least up to `jsdom@22.1.0`. See jestjs/jest#13825 (comment) for details. Upgrading to latest versions lets us improve some WheelEvent tests and will make it possible to test a much simpler FormData construction approach (see #29018) ## How did you test this change? Ran `yarn test` and `yarn test --prod` successfully
<> console.log(new URLSearchParams(formData).toString())}> VanillaCould you specify for which browser this piece of code is not working |
It doesn't work correctly in Chrome or Firefox, because React does not properly populate the the FormData object when the submitter is an Image Button. It "works" in Safari, but that's due to a browser bug. |
React version: canary
Steps To Reproduce
Link to code example
The current behavior
submitter=
is loggedThe expected behavior
Something like
submitter.x=5&submitter.y=10
should be loggedWhen an image submit button is activated, the form data set should include entries for the X and Y coordinates, indicating the relative position where the user clicked. This will keep the behavior consistent with a vanilla form submission (MDN explainer, relevant section of the HTML spec)
Additional commentary
We could probably just simplify all of this code to just
const formData = new FormData(form, submitter);
... the submitter parameter is widely available (87.42%); if we're concerned about browsers that don't support it, note that:SubmitEvent.submitter
, which means the existing approach won't work for them eitherIMO React doesn't need to maintain its own hacky partial polyfill for an increasingly diminishing edge case :)
See some previous discussion on the topic here.
The text was updated successfully, but these errors were encountered: