fix docs
[roojs1] / Roo / bootstrap / MoneyField.js
index 15f0c82..f681c79 100644 (file)
@@ -33,6 +33,10 @@ Roo.extend(Roo.bootstrap.MoneyField, Roo.bootstrap.ComboBox, {
      * @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)
      */
@@ -67,7 +71,10 @@ Roo.extend(Roo.bootstrap.MoneyField, Roo.bootstrap.ComboBox, {
      * @cfg {String} thousandsDelimiter Symbol of thousandsDelimiter
      */
     thousandsDelimiter : false,
-    
+    /**
+     * @cfg {Number} max_length Maximum input field length allowed (defaults to Number.MAX_VALUE)
+     */
+    max_length: false,
     
     inputlg : 9,
     inputmd : 9,
@@ -101,6 +108,10 @@ Roo.extend(Roo.bootstrap.MoneyField, Roo.bootstrap.ComboBox, {
             cls: 'hidden-number-input'
         };
         
+        if(this.max_length) {
+            input.maxlength = this.max_length; 
+        }
+        
         if (this.name) {
             hiddenInput.name = this.name;
         }
@@ -392,6 +403,10 @@ Roo.extend(Roo.bootstrap.MoneyField, Roo.bootstrap.ComboBox, {
             allowed += "-";
         }
         
+        if(this.thousandsDelimiter) {
+            allowed += ",";
+        }
+        
         this.stripCharsRe = new RegExp('[^'+allowed+']', 'gi');
         
         var keyPress = function(e){
@@ -536,23 +551,19 @@ Roo.extend(Roo.bootstrap.MoneyField, Roo.bootstrap.ComboBox, {
     
     setValue : function(v)
     {
-        v = this.fixPrecision(v);
+        v = String(this.fixPrecision(v)).replace(".", this.decimalSeparator);
         
-        v = String(v).replace(".", this.decimalSeparator);
-        
-        this.value = (v === null || v === undefined) ? '' : v;
+        this.value = v;
         
         if(this.rendered){
             
-            this.inputEl().dom.value = this.hiddenEl().dom.value = this.value;
+            this.hiddenEl().dom.value = (v === null || v === undefined ? '' : v);
             
-            if(this.allowDecimals && this.decimalPrecision != -1 && !isNaN(this.value)){
-                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 = '';
             }
             
@@ -574,18 +585,30 @@ Roo.extend(Roo.bootstrap.MoneyField, Roo.bootstrap.ComboBox, {
     
     parseValue : function(value)
     {
+        if(this.thousandsDelimiter) {
+            value += "";
+            r = new RegExp(",", "g");
+            value = value.replace(r, "");
+        }
+        
         value = parseFloat(String(value).replace(this.decimalSeparator, "."));
         return isNaN(value) ? '' : value;
+        
     },
     
     fixPrecision : function(value)
     {
+        if(this.thousandsDelimiter) {
+            value += "";
+            r = new RegExp(",", "g");
+            value = value.replace(r, "");
+        }
+        
         var nan = isNaN(value);
         
         if(!this.allowDecimals || this.decimalPrecision == -1 || nan || !value){
             return nan ? '' : value;
         }
-        
         return parseFloat(value).toFixed(this.decimalPrecision);
     },