You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by sy...@apache.org on 2005/08/19 16:27:39 UTC

svn commit: r233491 - /cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/resources/js/forms-lib.js

Author: sylvain
Date: Fri Aug 19 07:27:36 2005
New Revision: 233491

URL: http://svn.apache.org/viewcvs?rev=233491&view=rev
Log:
Fixing the "onsubmit called twice" problem

Modified:
    cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/resources/js/forms-lib.js

Modified: cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/resources/js/forms-lib.js
URL: http://svn.apache.org/viewcvs/cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/resources/js/forms-lib.js?rev=233491&r1=233490&r2=233491&view=diff
==============================================================================
--- cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/resources/js/forms-lib.js (original)
+++ cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/resources/js/forms-lib.js Fri Aug 19 07:27:36 2005
@@ -38,15 +38,20 @@
 
 function forms_onsubmit() {
     if (forms_onsubmitHandlers == null) {
-        alert("onsubmit called twice!");
-        return;
+        // Form already submited, but the new page is not yet loaded. This can happen when
+        // the focus is in an input with an "onchange" and the user clicks on a submit button.
+        return false;
     }
 
     for (var i = 0; i < forms_onsubmitHandlers.length; i++) {
-        forms_onsubmitHandlers[i].forms_onsubmit();
+        if (forms_onsubmitHandlers[i].forms_onsubmit() == false) {
+            // handler cancels the submit
+            return false;
+        	}
     }
     // clear it
     forms_onsubmitHandlers = null;
+    return true;
 }
 
 /**
@@ -64,8 +69,9 @@
     } else {
         form["forms_submit_id"].value = name;
         // FIXME: programmatically submitting the form doesn't trigger onsubmit ? (both in IE and Moz)
-        forms_onsubmit();
-        form.submit();
+        if (forms_onsubmit()) {
+            form.submit();
+        }
     }
 }