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

Fix Firefox post-validation submit handling #62

Merged
merged 6 commits into from
Jul 30, 2023
Merged

Conversation

dahlbyk
Copy link
Collaborator

@dahlbyk dahlbyk commented Jul 30, 2023

From #61 (comment):

Apparently #33 just doesn't work on Firefox. Here's a minimal repro and a proposed fix: https://codepen.io/dahlbyk/full/oNQQoMq.

image

In short, Firefox isn't firing submit listeners for the redispatch here:

submitValidForm = (form: HTMLFormElement, submitEvent: SubmitEvent) => {
const newEvent = new SubmitEvent('submit', submitEvent);
if (form.dispatchEvent(newEvent)) {

Using setTimeout(fn, 0) seems to allow the original submit handler to finish before dispatching at the next opportunity.

@dahlbyk dahlbyk requested a review from haacked July 30, 2023 21:01
src/index.ts Outdated Show resolved Hide resolved
Copy link
Owner

@haacked haacked left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit: Thanks!

@haacked haacked merged commit d910bd3 into main Jul 30, 2023
1 check passed
@haacked haacked deleted the fix-firefox-submit branch July 30, 2023 23:07
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.

Form e.preventDefault() broken in Firefox (0.8.3-0.8.13)
2 participants