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 was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tilboerner how does this still work?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It still works because with the other removed line in this patch, the default action for the click event is not prevented. That default action is to cause a 'submit' event on the form. (Note that the function containing the change is not handling the submit event itself, but the click event leading up to it. Preventing its default action means no submit event gets dispatched, and not submit event handlers get called, even if we later submit the form from the prototype.)
The submit event is then handled by the
form.onsubmit
function which was set below, on 'DOMContentLoaded':django-s3file/s3file/static/s3file/js/s3file.js
Lines 111 to 114 in 7e7656d
If I understand JS correctly, things proceed synchronously, and we can trust at this point that if the submit was triggered by a click, the click handler has added the hidden input to the form.
I found one caveat: When manually dispatching a click event for the button, it needs to be a
MouseEvent
to trigger the submit logic; a genericEvent("click")
triggers the click handler, but does not default to submitting the form. Without the change in this PR, any oldEvent
would do.However, the canonical click event is a MouseEvent, and gets dispatched as such even when triggering the button by keyboard or calling
button.click()
. All things considered, I think it's better to make the proposed change and honor the expectation of other submit handlers that they will be called on submit, rather than cater to code that is trying to use non-standard, non-MouseEvents
to trigger submit clicks.edit Forgot to mention @codingjoe. :)