add onfailure fonction for validateForm, return formid on success stable
authorKatia Saurfelt <katia.saurfelt@logilab.fr>
Tue, 19 May 2009 11:48:55 +0200
branchstable
changeset 1864 4ceaf8f2709b
parent 1863 9a02979a2c00
child 1865 62d3726ad8cb
add onfailure fonction for validateForm, return formid on success
web/data/cubicweb.edition.js
--- a/web/data/cubicweb.edition.js	Tue May 19 11:44:06 2009 +0200
+++ b/web/data/cubicweb.edition.js	Tue May 19 11:48:55 2009 +0200
@@ -342,11 +342,11 @@
 }
 
 
-function handleFormValidationResponse(formid, onsuccess, result) {
+function handleFormValidationResponse(formid, onsuccess, onfailure, result) {
     // Success
     if (result[0]) {
 	if (onsuccess) {
-	    return onsuccess(result[1]);
+	    return onsuccess(result[1], formid);
 	} else {
 	    document.location.href = result[1];
 	    return ;
@@ -365,6 +365,9 @@
     _displayValidationerrors(formid, descr[0], descr[1]);
     updateMessage(_("please correct errors below"));
     document.location.hash = '#header';
+    if (onfailure){
+	onfailure(formid);
+    }
     return false;
 }
 
@@ -426,7 +429,7 @@
  * to the appropriate URL. Otherwise, the validation errors are displayed
  * around the corresponding input fields.
  */
-function validateForm(formid, action, onsuccess) {
+function validateForm(formid, action, onsuccess, onfailure) {
     try {
 	var zipped = formContents(formid);
 	var d = asyncRemoteExec('validate_form', action, zipped[0], zipped[1]);
@@ -435,7 +438,7 @@
 	return false;
     }
     function _callback(result, req) {
-	handleFormValidationResponse(formid, onsuccess, result);
+	handleFormValidationResponse(formid, onsuccess, onfailure, result);
     }
     d.addCallback(_callback);
     return false;