allow string based values for comboboxarray
[roojs1] / Roo / bootstrap / NumberField.js
index 8c06d07..e82d69f 100644 (file)
@@ -1,8 +1,7 @@
 /*
  * - LGPL
  *
- * Input
- * 
+ * Number field 
  */
 
 /**
@@ -40,6 +39,11 @@ Roo.extend(Roo.bootstrap.NumberField, Roo.bootstrap.Input, {
      * @cfg {Boolean} allowNegative False to prevent entering a negative sign (defaults to true)
      */
     allowNegative : true,
+    
+    /**
+     * @cfg {Boolean} allowZero False to blank out if the user enters '0' (defaults to true)
+     */
+    allowZero: true,
     /**
      * @cfg {Number} minValue The minimum allowed value (defaults to Number.NEGATIVE_INFINITY)
      */
@@ -61,18 +65,10 @@ Roo.extend(Roo.bootstrap.NumberField, Roo.bootstrap.Input, {
      * if a valid character like '.' or '-' is left in the field with no number (defaults to "{value} is not a valid number")
      */
     nanText : "{0} is not a valid number",
-    /**
-     * @cfg {Boolean} castInt (true|false) cast int if true (defalut true)
-     */
-    castInt : true,
-    /**
-     * @cfg {Boolean} allowThousandsDelimiter (true|false) display thousands delimiter if true (e.g. "100,000") (defalut false)
-     */
-    allowThousandsDelimiter : false,
     /**
      * @cfg {String} thousandsDelimiter Symbol of thousandsDelimiter
      */
-    thousandsDelimiter : ",",
+    thousandsDelimiter : false,
     /**
      * @cfg {String} valueAlign alignment of value
      */
@@ -119,8 +115,8 @@ Roo.extend(Roo.bootstrap.NumberField, Roo.bootstrap.Input, {
             allowed += "-";
         }
         
-        if(this.allowThousandsDelimiter) {
-            allowed += this.thousandsDelimiter;
+        if(this.thousandsDelimiter) {
+            allowed += ",";
         }
         
         this.stripCharsRe = new RegExp('[^'+allowed+']', 'gi');
@@ -187,9 +183,9 @@ Roo.extend(Roo.bootstrap.NumberField, Roo.bootstrap.Input, {
 
     parseValue : function(value)
     {
-        if(this.allowThousandsDelimiter) {
+        if(this.thousandsDelimiter) {
             value += "";
-            r = new RegExp(this.thousandsDelimiter, "g");
+            r = new RegExp(",", "g");
             value = value.replace(r, "");
         }
         
@@ -199,9 +195,9 @@ Roo.extend(Roo.bootstrap.NumberField, Roo.bootstrap.Input, {
 
     fixPrecision : function(value)
     {
-        if(this.allowThousandsDelimiter) {
+        if(this.thousandsDelimiter) {
             value += "";
-            r = new RegExp(this.thousandsDelimiter, "g");
+            r = new RegExp(",", "g");
             value = value.replace(r, "");
         }
         
@@ -223,7 +219,13 @@ Roo.extend(Roo.bootstrap.NumberField, Roo.bootstrap.Input, {
             
             this.hiddenEl().dom.value = (v === null || v === undefined ? '' : v);
             
-            this.inputEl().dom.value = (this.allowThousandsDelimiter ? this.addThousandsDelimiter(v) : v);
+            this.inputEl().dom.value = (v == '') ? '' :
+                Roo.util.Format.number(v, this.decimalPrecision, this.thousandsDelimiter || '');
+            
+            if(!this.allowZero && v === '0') {
+                this.hiddenEl().dom.value = '';
+                this.inputEl().dom.value = '';
+            }
             
             this.validate();
         }
@@ -236,37 +238,11 @@ Roo.extend(Roo.bootstrap.NumberField, Roo.bootstrap.Input, {
 
     beforeBlur : function()
     {
-        if(!this.castInt){
-            return;
-        }
-        
         var v = this.parseValue(this.getRawValue());
-        if(v){
-            this.setValue(v);
-        }
-    },
-    
-    addThousandsDelimiter : function(v)
-    {
-        if(!this.allowThousandsDelimiter) {
-            return v;
-        }
-        
-        v += "";
         
-        var x = v.split(".");
-        
-        var x1 = x[0];
-        
-        var x2 = x.length > 1 ? "." + x[1] : "";
-        
-        var rgx = /(\d+)(\d{3})/;
-        
-        while (rgx.test(x1)) {
-            x1 = x1.replace(rgx, "$1" + this.thousandsDelimiter + "$2");
+        if(v || v === 0 || v === ''){
+            this.setValue(v);
         }
-        
-        return x1 + x2;
     },
     
     hiddenEl : function()