You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by "reiern70 (via GitHub)" <gi...@apache.org> on 2026/10/05 16:18:35 UTC
[PR] Keep Firefox from submitting a form for the triggered submit event [wicket]
reiern70 opened a new pull request, #1651:
URL: https://github.com/apache/wicket/pull/1651
Fixes #1650.
An `AjaxFormSubmitBehavior` whose `shouldTriggerJavaScriptSubmitEvent()` returns `true` fires a `submit` event on the form before its Ajax request (`UploadProgressBar` starts its bar from it). Since the jQuery-free engine (615af3ee95) the precondition fires it with `dispatchEvent()`. Firefox still submits a form for a submit event fired by a script unless the event is cancelled, so in Firefox the button sent its Ajax request **and** submitted the form normally, reloading the page behind the Ajax response. Chrome does not submit for such an event.
The precondition now calls a new `Wicket.Event.triggerSubmit(form)`, in both `wicket-ajax-jquery.js` and `wicket-ajax.js`. It fires the event, tells whether a submit handler cancelled it, and cancels it once it has bubbled up to the window, so no browser submits the form. A handler cancelling the event still stops the Ajax request.
Master only: Wicket 10.x triggers the event through jQuery and cancels it in its own handler, and was checked in Firefox not to submit.
Tests:
- QUnit `Wicket.Event.triggerSubmit` (4 tests in `event.js`), run in Chrome and Firefox with both engines.
- `AjaxFormSubmitBehaviorTest.theSubmitEventIsTriggeredWithoutSubmittingTheForm`.
- Checked by hand in Firefox 157 and Chrome with the Ajax upload example: one Ajax request, no reload.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@wicket.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Keep Firefox from submitting a form for the triggered submit event [wicket]
Posted by "codecov-commenter (via GitHub)" <gi...@apache.org>.
codecov-commenter commented on PR #1651:
URL: https://github.com/apache/wicket/pull/1651#issuecomment-5999375338
## [Codecov](https://app.codecov.io/gh/apache/wicket/pull/1651?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
:white_check_mark: All modified and coverable lines are covered by tests.
:white_check_mark: Project coverage is 61.95%. Comparing base ([`ee62ec8`](https://app.codecov.io/gh/apache/wicket/commit/ee62ec8c0149d19a9cb7e32d863be103c25cc0c1?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)) to head ([`ef55f0e`](https://app.codecov.io/gh/apache/wicket/commit/ef55f0ec92505528d3205ecb6a8294a533a240eb?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)).
:warning: Report is 4 commits behind head on master.
<details><summary>Additional details and impacted files</summary>
```diff
@@ Coverage Diff @@
## master #1651 +/- ##
=========================================
Coverage 61.95% 61.95%
- Complexity 11280 11281 +1
=========================================
Files 1250 1250
Lines 48429 48429
Branches 6792 6792
=========================================
+ Hits 30002 30006 +4
+ Misses 15729 15726 -3
+ Partials 2698 2697 -1
```
</details>
<details><summary> :rocket: New features to boost your workflow: </summary>
- :snowflake: [Test Analytics](https://docs.codecov.com/docs/test-analytics): Detect flaky tests, report on failures, and find test suite problems.
- :package: [JS Bundle Analysis](https://docs.codecov.com/docs/javascript-bundle-analysis): Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
</details>
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@wicket.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Keep Firefox from submitting a form for the triggered submit event [wicket]
Posted by "reiern70 (via GitHub)" <gi...@apache.org>.
reiern70 commented on code in PR #1651:
URL: https://github.com/apache/wicket/pull/1651#discussion_r4193986811
##########
wicket-core/src/main/java/org/apache/wicket/markup/html/form/Form.java:
##########
@@ -551,7 +554,7 @@ public final CharSequence getJsForListenerUrl(CharSequence url)
}
buffer.append(String.format("var f = document.getElementById('%s');", root.getMarkupId()));
buffer.append(String.format("f.action='%s';", action));
- buffer.append("Wicket.Event.fire(f, 'submit');");
+ buffer.append("if (Wicket.Event.triggerSubmit(f)) { f.submit(); }");
Review Comment:
`f.submit()` throws when the form contains a control named `submit`: a form control's name shadows the form's property, so `f.submit` is that element, not the method. In Wicket a control's `name` is its component path, so a button or field with the id `submit` directly in the form is enough (a common id; `AjaxFormSubmitBehaviorTest` uses it too). A `FormComponentUpdatingBehavior` then fails with `TypeError: f.submit is not a function` and the form is not submitted, with either Ajax engine. Before, the jQuery engine's `trigger()` only called the native method when it was a function.
Suggestion: `HTMLFormElement.prototype.submit.call(f);`
##########
wicket-core/src/main/java/org/apache/wicket/ajax/res/js/wicket-ajax.js:
##########
@@ -2785,6 +2785,47 @@
}
},
+ /**
+ * Fires a submit event on the given form, so that its submit handlers run, without
+ * submitting the form: an Ajax request submits it instead. Firefox submits a form for
+ * a submit event fired by a script unless the event is cancelled, so the event is
+ * cancelled once the handlers on the form have run, as the last listener on the form.
+ *
+ * @param form {HTMLFormElement} the form
+ * @returns {boolean} false if a handler on the form, or one capturing the event on its
+ * way there, cancelled the event
+ */
+ triggerSubmit: function(form) {
+ const event = new Event('submit', { cancelable: true, bubbles: true });
+ let cancelledByHandler = null;
+ const cancel = function () {
+ if (cancelledByHandler === null) {
+ cancelledByHandler = event.defaultPrevented;
+ event.preventDefault();
+ }
+ };
+ const cancelOwnEvent = function (e) {
+ if (e === event) {
+ cancel();
+ }
+ };
+ // a handler stopping the immediate propagation keeps cancelOwnEvent from running
+ const stopImmediatePropagation = event.stopImmediatePropagation;
Review Comment:
Only `stopImmediatePropagation()` is covered. A capturing `submit` listener on an ancestor (`document`, `body`) that calls `event.stopPropagation()` without cancelling keeps the event from reaching the form, so `cancelOwnEvent` never runs and the event is never cancelled: `triggerSubmit` returns `true`, the Ajax request goes out, and Firefox submits the form as well, the double submission this PR is about. Wrapping `event.stopPropagation` the same way would close it (with the caveat that other listeners on that same element still run afterwards and could no longer cancel the request).
##########
wicket-core/src/main/java/org/apache/wicket/ajax/res/js/wicket-ajax-jquery.js:
##########
@@ -2505,6 +2505,47 @@
}
},
+ /**
+ * Fires a submit event on the given form, so that its submit handlers run, without
+ * submitting the form: an Ajax request submits it instead. Firefox submits a form for
+ * a submit event fired by a script unless the event is cancelled, so the event is
+ * cancelled once the handlers on the form have run, as the last listener on the form.
+ *
+ * @param form {HTMLFormElement} the form
+ * @returns {boolean} false if a handler on the form, or one capturing the event on its
+ * way there, cancelled the event
+ */
+ triggerSubmit: function(form) {
+ const event = new Event('submit', { cancelable: true, bubbles: true });
+ let cancelledByHandler = null;
+ const cancel = function () {
+ if (cancelledByHandler === null) {
+ cancelledByHandler = event.defaultPrevented;
+ event.preventDefault();
+ }
+ };
+ const cancelOwnEvent = function (e) {
+ if (e === event) {
+ cancel();
+ }
+ };
+ // a handler stopping the immediate propagation keeps cancelOwnEvent from running
+ const stopImmediatePropagation = event.stopImmediatePropagation;
Review Comment:
Same as in wicket-ajax.js: `stopPropagation()` by a capturing ancestor isn't covered, so Firefox still submits the form besides the Ajax request.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@wicket.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Keep Firefox from submitting a form for the triggered submit event [wicket]
Posted by "reiern70 (via GitHub)" <gi...@apache.org>.
reiern70 closed pull request #1651: Keep Firefox from submitting a form for the triggered submit event
URL: https://github.com/apache/wicket/pull/1651
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@wicket.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Keep Firefox from submitting a form for the triggered submit event [wicket]
Posted by "papegaaij (via GitHub)" <gi...@apache.org>.
papegaaij commented on PR #1651:
URL: https://github.com/apache/wicket/pull/1651#issuecomment-6000762128
I'm looking at this PR, and it seems its not correct yet. The main issue is an event that never reaches window because of stopPropagation().
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@wicket.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Keep Firefox from submitting a form for the triggered submit event [wicket]
Posted by "reiern70 (via GitHub)" <gi...@apache.org>.
reiern70 commented on PR #1651:
URL: https://github.com/apache/wicket/pull/1651#issuecomment-6019882951
Superseded by #1652, which is merged now (2c89c796ce).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@wicket.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Keep Firefox from submitting a form for the triggered submit event [wicket]
Posted by "reiern70 (via GitHub)" <gi...@apache.org>.
reiern70 commented on PR #1651:
URL: https://github.com/apache/wicket/pull/1651#issuecomment-6000827483
> I'm looking at this PR, and it seems its not correct yet. The main issue is an event that never reaches window because of stopPropagation().
Maybe. I just found this while working on https://github.com/apache/wicket/pull/1637
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@wicket.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org