Skip events that already have default prevented #27
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There may be scenarios where you want to do client-side validation or have some other specialty handler for a form. In these scenarios, it would be nice to have an escape hatch that prevents
remoteForm
from handling the event.There are also some rare (but possible) edge cases with code bundlers where an app could double load this module and execute it twice, creating two registered listeners for form
submit
events. In this scenario, both instances ofremoteForm
would trigger their handlers and send the fetch request, causing a double submission.In both cases, a solution is to check if the event has already been handled by checking
event.defaultPrevented
. This allows custom handlers to prevent further action with the event, and handles the double load scenario because we already callpreventDefault
withinremoteForm
.This should fix an outstanding issue in github/github where comment creation and other actions can be executed twice.
Note: We may need to consider this a breaking change as it could prevent forms from submitting in apps that are already preventing default somewhere. Not sure how we typically handle unintended side-effects like this 馃槄