[js preferences] fix various pb with js for preferences form: buggy clearPreviousError, bad prototype of callbacks given to validate form, dunno how error display was expecting to work...
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Tue, 19 Oct 2010 17:57:56 +0200
changeset 6554 d60250252fc6
parent 6553 2be8ff05fd20
child 6555 f8b36b1e98bf
[js preferences] fix various pb with js for preferences form: buggy clearPreviousError, bad prototype of callbacks given to validate form, dunno how error display was expecting to work...
web/data/cubicweb.preferences.js
--- a/web/data/cubicweb.preferences.js	Tue Oct 19 17:14:19 2010 +0200
+++ b/web/data/cubicweb.preferences.js	Tue Oct 19 17:57:56 2010 +0200
@@ -46,19 +46,22 @@
 
 function validatePrefsForm(formid) {
     clearPreviousMessages();
-    clearPreviousErrors(formid);
+    _clearPreviousErrors(formid);
     return validateForm(formid, null, submitSucces, submitFailure);
 }
 
-function submitFailure(formid) {
+function submitFailure(result, formid, cbargs) {
     var $form = jQuery('#' + formid);
     var dom = DIV({'class': 'critical'}, _("please correct errors below"));
     $form.find('div.formsg').empty().append(dom);
-    // clearPreviousMessages()
+    unfreezeFormButtons(formid);
+    var descr = result[1];
+    _displayValidationerrors(formid, descr[0], descr[1]);
     $form.find('span.error').next().focus();
+    return false; // so handleFormValidationResponse doesn't try to display error
 }
 
-function submitSucces(url, formid) {
+function submitSucces(result, formid, cbargs) {
     var $form = jQuery('#' + formid);
     setCurrentValues($form);
     var dom = DIV({'class': 'msg'}, _("changes applied"));
@@ -73,10 +76,6 @@
     jQuery('div.formsg').empty();
 }
 
-function clearPreviousErrors(formid) {
-    jQuery('#err-value:' + formid).remove();
-}
-
 function checkValues(form, success) {
     var unfreezeButtons = false;
     jQuery(form).find('select').each(function() {
@@ -95,7 +94,7 @@
         if (!success) {
             clearPreviousMessages();
         }
-        clearPreviousErrors(form.attr('id'));
+        _clearPreviousErrors(form.attr('id'));
         freezeFormButtons(form.attr('id'));
     }
 }