allow string based values for comboboxarray
[roojs1] / Roo / bootstrap / NumberField.js
index 73c685e..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,10 +65,6 @@ 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 {String} thousandsDelimiter Symbol of thousandsDelimiter
      */
@@ -183,8 +183,6 @@ Roo.extend(Roo.bootstrap.NumberField, Roo.bootstrap.Input, {
 
     parseValue : function(value)
     {
-        Roo.log('phasign...');
-        
         if(this.thousandsDelimiter) {
             value += "";
             r = new RegExp(",", "g");
@@ -208,7 +206,6 @@ Roo.extend(Roo.bootstrap.NumberField, Roo.bootstrap.Input, {
         if(!this.allowDecimals || this.decimalPrecision == -1 || nan || !value){
             return nan ? '' : value;
         }
-        
         return parseFloat(value).toFixed(this.decimalPrecision);
     },
 
@@ -222,11 +219,11 @@ Roo.extend(Roo.bootstrap.NumberField, Roo.bootstrap.Input, {
             
             this.hiddenEl().dom.value = (v === null || v === undefined ? '' : v);
             
-            this.inputEl().dom.value = Roo.util.Format.number(v, this.decimalPrecision, 
-                this.thousandsDelimiter || ''
-            );
+            this.inputEl().dom.value = (v == '') ? '' :
+                Roo.util.Format.number(v, this.decimalPrecision, this.thousandsDelimiter || '');
             
-            if(this.allowBlank && !v) {
+            if(!this.allowZero && v === '0') {
+                this.hiddenEl().dom.value = '';
                 this.inputEl().dom.value = '';
             }
             
@@ -241,12 +238,9 @@ Roo.extend(Roo.bootstrap.NumberField, Roo.bootstrap.Input, {
 
     beforeBlur : function()
     {
-        if(!this.castInt){
-            return;
-        }
-        
         var v = this.parseValue(this.getRawValue());
-        if(v){
+        
+        if(v || v === 0 || v === ''){
             this.setValue(v);
         }
     },