[ 
https://issues.apache.org/jira/browse/WICKET-1448?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12908344#action_12908344
 ] 

Igor Vaynberg commented on WICKET-1448:
---------------------------------------

there is a problem with this. firing the submit event in firefox *submits* the 
form. so what we need to do is to call e.preventDefault() in some listener we 
install so that firefox does not submit the form and we can do it via ajax. 
however, since we are calling e.preventdefault() and the order of executions of 
listeners is not guaranteed we do not know if it is our handler that called 
e.preventdefault() or someone elses so we do not know when to abort the ajax 
submit. for now we will only support the invocation event added via the 
onsubmit attribute on the form tag, until someone comes up with a clean 
solution. see WICKET-3040 for the problem.

some of my notes on this for posterity:

Index: src/main/java/org/apache/wicket/markup/html/wicket-event.js
===================================================================
--- src/main/java/org/apache/wicket/markup/html/wicket-event.js (revision 
996162)
+++ src/main/java/org/apache/wicket/markup/html/wicket-event.js (working copy)
@@ -148,6 +148,14 @@
                        return element;
                },
                
+               remove: function(element, type, fn) {
+                       if (element.addEventListener) {
+                               element.removeEventListener(type, fn);
+                       } else {
+                               element.detachEvent('on'+type, fn);)
+                       }
+               }
+               
                // handlers that will be fired on dom ready event
                domReadyHandlers : new Array(),
                


Index: src/main/java/org/apache/wicket/ajax/wicket-ajax.js
===================================================================
--- src/main/java/org/apache/wicket/ajax/wicket-ajax.js (revision 996162)
+++ src/main/java/org/apache/wicket/ajax/wicket-ajax.js (working copy)
@@ -1093,10 +1093,20 @@
  // Submits a form using ajax.
  // This method serializes a form and sends it as POST body.
  submitForm: function(form, submitButton) {
- if (form.onsubmit) {
- if (!form.onsubmit()) return;
+
+ var canceller=function(e) {
+ if (e.preventDefault) { e.preventDefault(); }
+ else { e.returnValue=false;}
  }
-
+
+ Wicket.Event.add(form, "submit", canceller);
+
+ boolean ret=Wicket.Event.fire(form, "submit");
+
+ Wicket.Event.remove(form, "submit", canceller);
+
+ if (!ret) { /* abort */ return; }
+
  if (this.handleMultipart(form, submitButton)) {
  return true;
  }

> SubmitLink bypass jquery submit eventhandler
> --------------------------------------------
>
>                 Key: WICKET-1448
>                 URL: https://issues.apache.org/jira/browse/WICKET-1448
>             Project: Wicket
>          Issue Type: Bug
>          Components: wicket
>    Affects Versions: 1.3.2
>            Reporter: xiefei
>            Assignee: Igor Vaynberg
>             Fix For: 1.4.11, 1.5-M2
>
>
> <form id="wicketForm"><a href="#" wicket:id="submitLink">submit</a></form>
> if:
>         
> response.renderOnDomReadyJavascript("jQuery('#"+component.getMarkupId()+"').submit(function(){alert('x');return
>  false;})");
> the alert will not show when submitLink is clicked, and the form is submitted
> if: 
>         
> response.renderOnDomReadyJavascript("document.getElementById('"+component.getMarkupId()+"').onsubmit
>  = function(){alert('x');return false;}");
> the alert will show and the form is not submmitted

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to