Fixes issue 28469: Masked string validation is properly done in editable grid
authorAugusto Mauch <augusto.mauch@openbravo.com>
Mon, 05 Jan 2015 13:38:32 +0100
changeset 25720 b614afc46817
parent 25719 675fc7b4fbac
child 25721 aafc50f0ea12
child 25727 33b8eec9e03f
Fixes issue 28469: Masked string validation is properly done in editable grid

There were several problems that were preventing the handling of masked string validations from working properly:
1- The masked string validations were not being performed in grid view, due to this code in the validate function:

if (this.form && this.form.grid && this.form.grid._showingEditor) {
return;
}

That code was put there to prevent doing unneeded validations when a new record was created in the grid view (see issue https://issues.openbravo.com/view.php?id=19176). This issue remains fixed after re
moving these lines.

2- After fixing 1), the Save toolbar button was enabled in the grid view even if the row being edited had masked string validation errores. These happened because of a flaw in the logic to disable the butt
on:

this.setDisabled(... && !hasErrors && ...);

The button was being disabled when the editable form did not have errors, and enabled when the form had errors. Before fixing 1) this did not matter, as hasErrors was always false because the form item
was not being validated. This has been fixed by disabling the button when the form had validation errors.

3- Sometimes (i.e. when the validation was performed due to an autosave) the mask validation was not taken into account. This happened because the validation was added to the validation list of the test it
em, but not to the validation list of the grid field, that is where it was being taken from.
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/formitem/ob-formitem-text.js
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/toolbar/ob-toolbar.js
modules/org.openbravo.userinterface.smartclient/web/org.openbravo.userinterface.smartclient/js/ob-smartclient.js
--- a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/formitem/ob-formitem-text.js	Mon Dec 29 18:34:58 2014 +0100
+++ b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/formitem/ob-formitem-text.js	Mon Jan 05 13:38:32 2015 +0100
@@ -39,6 +39,7 @@
   },
 
   resetMaskValidator: function (createNew) {
+    var gridField;
     if (this.maskValidator && this.validators) {
       this.validators.remove(this.maskValidator);
       delete this.maskValidator;
@@ -49,6 +50,13 @@
       this.validators = this.validators || [];
       this.validators.push(this.maskValidator);
     }
+    if (this.grid) {
+      gridField = this.grid.getField(this.name);
+      if (gridField) {
+        // update the validators of the grid field, so that it is taken into account in the ListGrid.validateRowValues function
+        gridField.validators = this.validators;
+      }
+    }
   },
 
   createRegExpFromMask: function (mask) {
--- a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/toolbar/ob-toolbar.js	Mon Dec 29 18:34:58 2014 +0100
+++ b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/toolbar/ob-toolbar.js	Mon Jan 05 13:38:32 2015 +0100
@@ -52,7 +52,7 @@
         form = view.viewGrid.getEditForm();
         editRow = view.viewGrid.getEditRow();
         hasErrors = view.viewGrid.rowHasErrors(editRow);
-        this.setDisabled(!(form.isNew && form.allRequiredFieldsSet()) && !hasErrors && (form.isSaving || form.readOnly || !view.hasValidState() || form.hasErrors() || !form.hasChanged || !form.allRequiredFieldsSet()));
+        this.setDisabled(!(form.isNew && form.allRequiredFieldsSet()) && (form.isSaving || form.readOnly || !view.hasValidState() || hasErrors || form.hasErrors() || !form.hasChanged || !form.allRequiredFieldsSet()));
       } else {
         this.setDisabled(true);
       }
--- a/modules/org.openbravo.userinterface.smartclient/web/org.openbravo.userinterface.smartclient/js/ob-smartclient.js	Mon Dec 29 18:34:58 2014 +0100
+++ b/modules/org.openbravo.userinterface.smartclient/web/org.openbravo.userinterface.smartclient/js/ob-smartclient.js	Mon Jan 05 13:38:32 2015 +0100
@@ -553,9 +553,6 @@
 
     // prevent validation when we are showing the editor and moving
     // the focus around
-    if (this.form && this.form.grid && this.form.grid._showingEditor) {
-      return;
-    }
 
     if (this.preventValidation) {
       return;