Roo/form/NumberField.js
authorAlan <alan@roojs.com>
Wed, 27 Mar 2024 05:01:52 +0000 (13:01 +0800)
committerAlan <alan@roojs.com>
Wed, 27 Mar 2024 05:01:52 +0000 (13:01 +0800)
Roo/form/NumberField.js

index 84cc17d..5f468f3 100644 (file)
@@ -73,7 +73,7 @@ Roo.extend(Roo.form.NumberField, Roo.form.TextField,  {
      
     onRender : function(ct, position)
     {
-        Roo.form.DateField.superclass.onRender.call(this, ct, position);
+        Roo.form.TextField.superclass.onRender.call(this, ct, position);
     
             //this.el.dom.removeAttribute('name'); 
         Roo.log("Changing name?");
@@ -82,12 +82,37 @@ Roo.extend(Roo.form.NumberField, Roo.form.TextField,  {
             this.hiddenField = this.el.insertSibling({ tag:'input', type:'hidden', name: this.name },
                         'before', true);
             this.hiddenField.value = this.value ? this.parseValue(this.value) : '';
+            this.el.on('blur', this.onBlur, this);
         }
         
             // prevent input submission
         
             
             
+    },
+     onBlur : function(){
+        this.beforeBlur();
+        if(!Roo.isOpera && this.focusClass){ // don't touch in Opera
+            this.el.removeClass(this.focusClass);
+        }
+        this.hasFocus = false;
+        if(this.validationEvent !== false && this.validateOnBlur && this.validationEvent != "blur"){
+            this.validate();
+        }
+        var v = this.getValue();
+        if(String(v) !== String(this.startValue)){
+            this.setValue( this.parseValue(v));
+            this.fireEvent('change', this, v, this.startValue);
+        }
+        this.fireEvent("blur", this);
+    },
+    
+    // override name, so that it works with hidden field.
+    getName: function(){
+        if (this.thousandSeparator != '') {
+            return this.name;
+        }
+        return Roo.form.TextField.superclass.getName.call(this);
     },
     // private
     initEvents : function(){
@@ -144,7 +169,7 @@ Roo.extend(Roo.form.NumberField, Roo.form.TextField,  {
 
     // private
     parseValue : function(value){
-        value = parseFloat(String(value).replace(this.decimalSeparator, ".").replace(this.thousandSeparator, ''));
+        value = parseFloat(String(value).replace(this.decimalSeparator, ".").split(this.thousandSeparator).join(''));
         return isNaN(value) ? '' : value;
     },
 
@@ -160,7 +185,7 @@ Roo.extend(Roo.form.NumberField, Roo.form.TextField,  {
     setValue : function(v){
         v = this.fixPrecision(v);
         if(this.thousandSeparator != ''){
-       //     v = Roo.util.Format.number(v, this.decimalPrecision, this.thousandSeparator);
+            v = Roo.util.Format.number(v, this.decimalPrecision, this.thousandSeparator);
         } 
         Roo.form.NumberField.superclass.setValue.call(this, String(v).replace(".", this.decimalSeparator));
         if (this.hiddenField !== false) {