details:   https://code.openbravo.com/erp/devel/pi/rev/45f5ddc6e578
changeset: 13763:45f5ddc6e578
user:      Martin Taal <martin.taal <at> openbravo.com>
date:      Tue Sep 13 10:46:40 2011 +0200
summary:   Fixes issue 18513: Expressions in numeric fields do not work anymore
Moved conversion to validator, replace global validors for float and integer

diffstat:

 
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/formitem/ob-formitem-number.js
 |  99 ++++-----
 
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/ob-view-form.js
                |   3 +-
 2 files changed, 46 insertions(+), 56 deletions(-)

diffs (147 lines):

diff -r 4f0b9e95b000 -r 45f5ddc6e578 
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/formitem/ob-formitem-number.js
--- 
a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/formitem/ob-formitem-number.js
      Tue Sep 13 10:16:22 2011 +0200
+++ 
b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/formitem/ob-formitem-number.js
      Tue Sep 13 10:46:40 2011 +0200
@@ -40,18 +40,6 @@
     
     this.setKeyPressFilter(this.keyPressFilterNumeric);
     this.typeInstance = SimpleType.getType(this.type);
-    var newValidators = [], i;
-    // get rid of the isFloat validators, as we have 
-    // specific validation based on the format definition
-    for (i = 0; i < length; i++) {
-      if (this.validators[i].type !== 'isFloat') {
-        newValidators.push(this.validators[i]);
-      }
-      if (this.validators[i].type === 'custom') {
-        this.valueValidator = this.validators[i];
-      }
-    }
-    this.validators = newValidators;
     return this.Super('init', arguments);
   },
   
@@ -442,24 +430,10 @@
   
   blur: function(){
     if (this.doBlurLogic) {
-      var value = this.getElementValue().toString();
-      var expressionValue;
-      var obj = this;
-      if (this.allowMath && value.indexOf('=') === 0) {
-        expressionValue = this.evalMathExpression(value);
-        if (expressionValue !== 'error') {
-          expressionValue = parseFloat(expressionValue, 10);
-        } else {
-          setTimeout(function() {
-            obj.setElementValue(value);
-          }, 50);
-          return this.Super('blur', arguments);
-        }
-        this.setValue(expressionValue);
-        this.validate();
-      }
-  
+      this.validate();  
+
       value = this.getValue();
+      
       // first check if the number is valid
       if (!isc.isA.String(value)) {
         // format the value displayed
@@ -467,33 +441,50 @@
       }
     }
     return this.Super('blur', arguments);
-  },
+  }
+});
+
+// Use our custom validator for float and integers
+isc.OBNumberItem.validateCondition = function(item, validator, value){
+  var ret, type;
   
-  validators: [{
-    type: 'custom',
-    condition: function(item, validator, value){
-      if (!item.typeInstance) {
-        // this happens when data is validated which is returned from the 
system
-        // and added to the grid
-        return true;
+  if (!item.typeInstance) {
+    // this happens when data is validated which is returned from the system
+    // and added to the grid
+    return true;
+  }
+  
+  if (item.allowMath && isc.isA.String(value) && value.indexOf('=') === 0) {
+    value = String('') + item.evalMathExpression(value);
+  }
+  
+  type = item.typeInstance;
+  validator.resultingValue = null;
+
+  // return a formatted value, if it was valid
+  if (isc.isA.String(value)) {
+    if (OB.Utilities.Number.IsValidValueString(type, value)) {
+      validator.resultingValue = OB.Utilities.Number.OBMaskedToJS(value, 
type.decSeparator, type.groupSeparator);
+      item.storeValue(validator.resultingValue);
+      if (item.form && item.form.setTextualValue) {
+        item.form.setTextualValue(item.name, value, item.typeInstance);
       }
-      var type = item.typeInstance;
-      this.resultingValue = null;
-      
-      
-      // return a formatted value, if it was valid
-      if (isc.isA.String(value)) {
-        if (OB.Utilities.Number.IsValidValueString(type, value)) {
-          this.resultingValue = OB.Utilities.Number.OBMaskedToJS(value, 
type.decSeparator, type.groupSeparator);
-          return true;
-        } else {
-          return false;
-        }
-      }
-      return OB.Utilities.Number.IsValidValueString(type, 
item.getElementValue());
+      return true;
+    } else {
+      // don't loose illegal values
+      validator.resultingValue = item.getElementValue();
+      return false;
     }
-  }]
-});
+  } else if (isc.isA.Number(value)) {
+    return true;
+  }
+  // don't loose illegal values
+  validator.resultingValue = item.getElementValue();
+  return false;
+};
+
+Validator.addValidator('isFloat', isc.OBNumberItem.validateCondition);
+Validator.addValidator('isInteger', isc.OBNumberItem.validateCondition);
 
 isc.ClassFactory.defineClass('OBNumberFilterItem', OBNumberItem);
 
@@ -501,7 +492,7 @@
   allowExpressions: true,
   validateOnExit: false,
   validateOnChange: false,
-  keyPressFilterNumeric: '[0-9.,-=<>!#]',
+  keyPressFilterNumeric: '[0-9.,-=<>!#orand ]',
   doBlurLogic: false,
   operator: 'equals',
   validOperators: ['equals', 'lessThan', 'greaterThan',
diff -r 4f0b9e95b000 -r 45f5ddc6e578 
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/ob-view-form.js
--- 
a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/ob-view-form.js
     Tue Sep 13 10:16:22 2011 +0200
+++ 
b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/ob-view-form.js
     Tue Sep 13 10:46:40 2011 +0200
@@ -1158,8 +1158,7 @@
     
     // store the value of the current focus item
     if (this.getFocusItem() && this.saveFocusItemChanged !== 
this.getFocusItem()) {
-      this.getFocusItem().updateValue();
-      this.handleItemChange(this.getFocusItem());
+      this.getFocusItem().blur(this, this.getFocusItem());
       // prevent infinite loops
       this.saveFocusItemChanged = this.getFocusItem();
     } else {

------------------------------------------------------------------------------
BlackBerry&reg; DevCon Americas, Oct. 18-20, San Francisco, CA
Learn about the latest advances in developing for the 
BlackBerry&reg; mobile platform with sessions, labs & more.
See new tools and technologies. Register for BlackBerry&reg; DevCon today!
http://p.sf.net/sfu/rim-devcon-copy1 
_______________________________________________
Openbravo-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openbravo-commits

Reply via email to