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

Support form submitter #2490

Merged
merged 1 commit into from
Feb 27, 2023
Merged

Support form submitter #2490

merged 1 commit into from
Feb 27, 2023

Conversation

mcrumm
Copy link
Member

@mcrumm mcrumm commented Feb 26, 2023

Adds support for SubmitEvent.submitter, which as of February 2023 is supported by 91.49% of browsers.

Additionally there is event-submitter-polyfill which is called out in the README for older browsers.

Closes #2148, related to #184, related to #511

@chrismccord chrismccord merged commit 847c704 into master Feb 27, 2023
@chrismccord
Copy link
Member

❤️❤️❤️🐥🔥

@chrismccord chrismccord deleted the mc-form-submitter branch February 27, 2023 19:50
@jbosse
Copy link

jbosse commented Apr 12, 2023

I love it when the thing you need is already updated and you just need to update your package. 🥇

@Rio517
Copy link
Contributor

Rio517 commented Jun 19, 2023

Also, as of 7581dcd, there is a put_submitter function for use in tests.

s3cur3 added a commit to s3cur3/phoenix_live_view that referenced this pull request Oct 12, 2023
This fixes an issue we discovered at Felt, which was introduced in phoenixframework#2490.

The symptoms were as follows:

- Given a form with an image upload, if you waited until the upload completed before submitting the form, the submission would work as expected.
- However, if you submitted before the upload completed, you'd see the submission correctly wait until the upload hit 100%, then you'd get a JavaScript crash and the app would go dead.

The JavaScript console produced an error like this in release:

```
TypeError: r.hasAttribute is not a function. (In 'r.hasAttribute("name")', 'r.hasAttribute' is undefined)
```

The error in dev, of course, was more descriptive:

```
submitter.hasAttribute is not a function
Call Stack
 serializeForm  node_modules/phoenix_live_view/priv/static/phoenix_live_view.esm.js:2402:30
 pushFormSubmit  node_modules/phoenix_live_view/priv/static/phoenix_live_view.esm.js:3308:35
 push  node_modules/phoenix_live_view/priv/static/phoenix_live_view.esm.js:3293:29
 triggerAwaitingSubmit  node_modules/phoenix_live_view/priv/static/phoenix_live_view.esm.js:3236:7
 pushInput/  node_modules/phoenix_live_view/priv/static/phoenix_live_view.esm.js:3223:18
 uploadFiles/  node_modules/phoenix_live_view/priv/static/phoenix_live_view.esm.js:3325:11
 initAdapterUpload/this._entries  node_modules/phoenix_live_view/priv/static/phoenix_live_view.esm.js:895:16
 onDone/this._onDone  node_modules/phoenix_live_view/priv/static/phoenix_live_view.esm.js:769:7
 progress/<  node_modules/phoenix_live_view/priv/static/phoenix_live_view.esm.js:745:16
 finish  node_modules/phoenix_live_view/priv/static/phoenix_live_view.esm.js:3034:18
```

Inspecting the code, it looks like the argument order got swapped in the case where uploads are in progress at form submission time.

I'm not sure how to write an adequate test to cover this, but I can confirm that the fix when applied to my codebase does indeed fix the issue.
chrismccord pushed a commit that referenced this pull request Oct 17, 2023
This fixes an issue we discovered at Felt, which was introduced in #2490.

The symptoms were as follows:

- Given a form with an image upload, if you waited until the upload completed before submitting the form, the submission would work as expected.
- However, if you submitted before the upload completed, you'd see the submission correctly wait until the upload hit 100%, then you'd get a JavaScript crash and the app would go dead.

The JavaScript console produced an error like this in release:

```
TypeError: r.hasAttribute is not a function. (In 'r.hasAttribute("name")', 'r.hasAttribute' is undefined)
```

The error in dev, of course, was more descriptive:

```
submitter.hasAttribute is not a function
Call Stack
 serializeForm  node_modules/phoenix_live_view/priv/static/phoenix_live_view.esm.js:2402:30
 pushFormSubmit  node_modules/phoenix_live_view/priv/static/phoenix_live_view.esm.js:3308:35
 push  node_modules/phoenix_live_view/priv/static/phoenix_live_view.esm.js:3293:29
 triggerAwaitingSubmit  node_modules/phoenix_live_view/priv/static/phoenix_live_view.esm.js:3236:7
 pushInput/  node_modules/phoenix_live_view/priv/static/phoenix_live_view.esm.js:3223:18
 uploadFiles/  node_modules/phoenix_live_view/priv/static/phoenix_live_view.esm.js:3325:11
 initAdapterUpload/this._entries  node_modules/phoenix_live_view/priv/static/phoenix_live_view.esm.js:895:16
 onDone/this._onDone  node_modules/phoenix_live_view/priv/static/phoenix_live_view.esm.js:769:7
 progress/<  node_modules/phoenix_live_view/priv/static/phoenix_live_view.esm.js:745:16
 finish  node_modules/phoenix_live_view/priv/static/phoenix_live_view.esm.js:3034:18
```

Inspecting the code, it looks like the argument order got swapped in the case where uploads are in progress at form submission time.

I'm not sure how to write an adequate test to cover this, but I can confirm that the fix when applied to my codebase does indeed fix the issue.
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

Successfully merging this pull request may close these issues.

4 participants