From: Alan
Date: Wed, 27 Mar 2024 05:02:46 +0000 (+0800)
Subject: Fix #8117 - another go at thousand seperator
X-Git-Url: http://git.roojs.org/?p=roojs1;a=commitdiff_plain;h=6c9ff83b9aeb60ee31ddcb2ccacc2b72bd3ba647
Fix #8117 - another go at thousand seperator
---
diff --git a/Roo/form/NumberField.js b/Roo/form/NumberField.js
index ac0ab795e7..5f468f3a6c 100644
--- a/Roo/form/NumberField.js
+++ b/Roo/form/NumberField.js
@@ -68,10 +68,55 @@ Roo.extend(Roo.form.NumberField, Roo.form.TextField, {
* 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",
-
+
+ hiddenField : false,
+
+ onRender : function(ct, position)
+ {
+ Roo.form.TextField.superclass.onRender.call(this, ct, position);
+
+ //this.el.dom.removeAttribute('name');
+ Roo.log("Changing name?");
+ if (this.thousandSeparator != '') {
+ this.el.dom.setAttribute('name', this.name + '____hidden___' );
+ 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(){
- Roo.form.NumberField.superclass.initEvents.call(this);
+
var allowed = "0123456789";
if(this.allowDecimals){
allowed += this.decimalSeparator;
@@ -124,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;
},
@@ -140,9 +185,14 @@ 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) {
+ this.hiddenField.value = v ? this.parseValue(v) : '';
+ }
+
+
},
// private
diff --git a/Roo/form/TextField.js b/Roo/form/TextField.js
index d3656053de..f3e6c741f3 100644
--- a/Roo/form/TextField.js
+++ b/Roo/form/TextField.js
@@ -132,9 +132,9 @@ Roo.extend(Roo.form.TextField, Roo.form.Field, {
if(this.selectOnFocus){
this.on("focus", this.preFocus, this);
}
- if (!this.allowLeadingSpace) {
- this.on('blur', this.cleanLeadingSpace, this);
- }
+ if (!this.allowLeadingSpace) {
+ this.on('blur', this.cleanLeadingSpace, this);
+ }
if(this.maskRe || (this.vtype && this.disableKeyFilter !== true && (this.maskRe = Roo.form.VTypes[this.vtype+'Mask']))){
this.el.on("keypress", this.filterKeys, this);
diff --git a/docs/src/Roo_form_NumberField.js.html b/docs/src/Roo_form_NumberField.js.html
index b93e989bf6..8628fa940f 100644
--- a/docs/src/Roo_form_NumberField.js.html
+++ b/docs/src/Roo_form_NumberField.js.html
@@ -69,9 +69,54 @@
*/
nanText : "{0} is not a valid number",
+ hiddenField : false,
+
+ onRender : function(ct, position)
+ {
+ Roo.form.TextField.superclass.onRender.call(this, ct, position);
+
+ Roo.log("Changing name?");
+ if (this.thousandSeparator != '') {
+ this.el.dom.setAttribute('name', this.name + '____hidden___' );
+ 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);
+ }
+
+ },
+ onBlur : function(){
+ this.beforeBlur();
+ if(!Roo.isOpera && this.focusClass){ 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);
+ },
+
+ getName: function(){
+ if (this.thousandSeparator != '') {
+ return this.name;
+ }
+ return Roo.form.TextField.superclass.getName.call(this);
+ },
initEvents : function(){
- Roo.form.NumberField.superclass.initEvents.call(this);
+
var allowed = "0123456789";
if(this.allowDecimals){
allowed += this.decimalSeparator;
@@ -124,7 +169,7 @@
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;
},
@@ -140,9 +185,14 @@
setValue : function(v){
v = this.fixPrecision(v);
if(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) {
+ this.hiddenField.value = v ? this.parseValue(v) : '';
+ }
+
+
},
if(this.selectOnFocus){
this.on("focus", this.preFocus, this);
}
- if (!this.allowLeadingSpace) {
- this.on('blur', this.cleanLeadingSpace, this);
- }
+ if (!this.allowLeadingSpace) {
+ this.on('blur', this.cleanLeadingSpace, this);
+ }
if(this.maskRe || (this.vtype && this.disableKeyFilter !== true && (this.maskRe = Roo.form.VTypes[this.vtype+'Mask']))){
this.el.on("keypress", this.filterKeys, this);
diff --git a/roojs-all.js b/roojs-all.js
index cc7a3526ac..cc5ff6eab8 100644
--- a/roojs-all.js
+++ b/roojs-all.js
@@ -1821,13 +1821,17 @@ Roo.form.TextArea=function(A){Roo.form.TextArea.superclass.constructor.call(this
}var el=this.el;var v=el.dom.value;var ts=this.textSizeEl;ts.innerHTML='';ts.appendChild(document.createTextNode(v));v=ts.innerHTML;Roo.fly(ts).setWidth(this.el.getWidth());if(v.length<1){v=" ";}else{if(Roo.isIE){v=v.replace(/\n/g,'
');
}v+=" \n ";}ts.innerHTML=v;var h=Math.min(this.growMax,Math.max(ts.offsetHeight,this.growMin));if(h!=this.lastHeight){this.lastHeight=h;this.el.setHeight(h);this.fireEvent("autosize",this,h);}}});
// Roo/form/NumberField.js
-Roo.form.NumberField=function(A){Roo.form.NumberField.superclass.constructor.call(this,A);};Roo.extend(Roo.form.NumberField,Roo.form.TextField,{fieldClass:"x-form-field x-form-num-field",allowDecimals:true,decimalSeparator:".",thousandSeparator:"",decimalPrecision:2,allowNegative:true,minValue:Number.NEGATIVE_INFINITY,maxValue:Number.MAX_VALUE,minText:"The minimum value for this field is {0}",maxText:"The maximum value for this field is {0}",nanText:"{0} is not a valid number",initEvents:function(){Roo.form.NumberField.superclass.initEvents.call(this);
-var A="0123456789";if(this.allowDecimals){A+=this.decimalSeparator;}A+=this.thousandSeparator;if(this.allowNegative){A+="-";}this.stripCharsRe=new RegExp('[^'+A+']','gi');var B=function(e){var k=e.getKey();if(!Roo.isIE&&(e.isSpecialKey()||k==e.BACKSPACE||k==e.DELETE)){return;
+Roo.form.NumberField=function(A){Roo.form.NumberField.superclass.constructor.call(this,A);};Roo.extend(Roo.form.NumberField,Roo.form.TextField,{fieldClass:"x-form-field x-form-num-field",allowDecimals:true,decimalSeparator:".",thousandSeparator:"",decimalPrecision:2,allowNegative:true,minValue:Number.NEGATIVE_INFINITY,maxValue:Number.MAX_VALUE,minText:"The minimum value for this field is {0}",maxText:"The maximum value for this field is {0}",nanText:"{0} is not a valid number",hiddenField:false,onRender:function(ct,A){Roo.form.TextField.superclass.onRender.call(this,ct,A);
+Roo.log("Changing name?");if(this.thousandSeparator!=''){this.el.dom.setAttribute('name',this.name+'____hidden___');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);}},onBlur:function(){this.beforeBlur();if(!Roo.isOpera&&this.focusClass){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);},getName:function(){if(this.thousandSeparator!=''){return this.name;}return Roo.form.TextField.superclass.getName.call(this);
+},initEvents:function(){var A="0123456789";if(this.allowDecimals){A+=this.decimalSeparator;}A+=this.thousandSeparator;if(this.allowNegative){A+="-";}this.stripCharsRe=new RegExp('[^'+A+']','gi');var B=function(e){var k=e.getKey();if(!Roo.isIE&&(e.isSpecialKey()||k==e.BACKSPACE||k==e.DELETE)){return;
}var c=e.getCharCode();if(A.indexOf(String.fromCharCode(c))===-1){e.stopEvent();}};this.el.on("keypress",B,this);},validateValue:function(A){if(!Roo.form.NumberField.superclass.validateValue.call(this,A)){return false;}if(A.length<1){return true;}var B=this.parseValue(A);
if(isNaN(B)){this.markInvalid(String.format(this.nanText,A));return false;}if(Bthis.maxValue){this.markInvalid(String.format(this.maxText,this.maxValue));return false;
-}return true;},getValue:function(){return this.fixPrecision(this.parseValue(Roo.form.NumberField.superclass.getValue.call(this)));},parseValue:function(A){A=parseFloat(String(A).replace(this.decimalSeparator,".").replace(this.thousandSeparator,''));return isNaN(A)?'':A;
-},fixPrecision:function(A){var B=isNaN(A);if(!this.allowDecimals||this.decimalPrecision==-1||B||!A){return B?'':A;}return parseFloat(A).toFixed(this.decimalPrecision);},setValue:function(v){v=this.fixPrecision(v);if(this.thousandSeparator!=''){}Roo.form.NumberField.superclass.setValue.call(this,String(v).replace(".",this.decimalSeparator));
-},decimalPrecisionFcn:function(v){return Math.floor(v);},beforeBlur:function(){var v=this.parseValue(this.getRawValue());if(v){this.setValue(v);}}});
+}return true;},getValue:function(){return this.fixPrecision(this.parseValue(Roo.form.NumberField.superclass.getValue.call(this)));},parseValue:function(A){A=parseFloat(String(A).replace(this.decimalSeparator,".").split(this.thousandSeparator).join(''));return isNaN(A)?'':A;
+},fixPrecision:function(A){var B=isNaN(A);if(!this.allowDecimals||this.decimalPrecision==-1||B||!A){return B?'':A;}return parseFloat(A).toFixed(this.decimalPrecision);},setValue:function(v){v=this.fixPrecision(v);if(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){this.hiddenField.value=v?this.parseValue(v):'';}},decimalPrecisionFcn:function(v){return Math.floor(v);},beforeBlur:function(){var v=this.parseValue(this.getRawValue());
+if(v){this.setValue(v);}}});
// Roo/form/DateField.js
Roo.form.DateField=function(A){Roo.form.DateField.superclass.constructor.call(this,A);this.addEvents({'select':true});if(typeof this.minValue=="string"){this.minValue=this.parseDate(this.minValue);}if(typeof this.maxValue=="string"){this.maxValue=this.parseDate(this.maxValue);
}this.ddMatch=null;if(this.disabledDates){var dd=this.disabledDates;var re="(?:";for(var i=0;i
');
}v+=" \n ";}ts.innerHTML=v;var h=Math.min(this.growMax,Math.max(ts.offsetHeight,this.growMin));if(h!=this.lastHeight){this.lastHeight=h;this.el.setHeight(h);this.fireEvent("autosize",this,h);}}});
// Roo/form/NumberField.js
-Roo.form.NumberField=function(A){Roo.form.NumberField.superclass.constructor.call(this,A);};Roo.extend(Roo.form.NumberField,Roo.form.TextField,{fieldClass:"x-form-field x-form-num-field",allowDecimals:true,decimalSeparator:".",thousandSeparator:"",decimalPrecision:2,allowNegative:true,minValue:Number.NEGATIVE_INFINITY,maxValue:Number.MAX_VALUE,minText:"The minimum value for this field is {0}",maxText:"The maximum value for this field is {0}",nanText:"{0} is not a valid number",initEvents:function(){Roo.form.NumberField.superclass.initEvents.call(this);
-var A="0123456789";if(this.allowDecimals){A+=this.decimalSeparator;}A+=this.thousandSeparator;if(this.allowNegative){A+="-";}this.stripCharsRe=new RegExp('[^'+A+']','gi');var B=function(e){var k=e.getKey();if(!Roo.isIE&&(e.isSpecialKey()||k==e.BACKSPACE||k==e.DELETE)){return;
+Roo.form.NumberField=function(A){Roo.form.NumberField.superclass.constructor.call(this,A);};Roo.extend(Roo.form.NumberField,Roo.form.TextField,{fieldClass:"x-form-field x-form-num-field",allowDecimals:true,decimalSeparator:".",thousandSeparator:"",decimalPrecision:2,allowNegative:true,minValue:Number.NEGATIVE_INFINITY,maxValue:Number.MAX_VALUE,minText:"The minimum value for this field is {0}",maxText:"The maximum value for this field is {0}",nanText:"{0} is not a valid number",hiddenField:false,onRender:function(ct,A){Roo.form.TextField.superclass.onRender.call(this,ct,A);
+Roo.log("Changing name?");if(this.thousandSeparator!=''){this.el.dom.setAttribute('name',this.name+'____hidden___');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);}},onBlur:function(){this.beforeBlur();if(!Roo.isOpera&&this.focusClass){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);},getName:function(){if(this.thousandSeparator!=''){return this.name;}return Roo.form.TextField.superclass.getName.call(this);
+},initEvents:function(){var A="0123456789";if(this.allowDecimals){A+=this.decimalSeparator;}A+=this.thousandSeparator;if(this.allowNegative){A+="-";}this.stripCharsRe=new RegExp('[^'+A+']','gi');var B=function(e){var k=e.getKey();if(!Roo.isIE&&(e.isSpecialKey()||k==e.BACKSPACE||k==e.DELETE)){return;
}var c=e.getCharCode();if(A.indexOf(String.fromCharCode(c))===-1){e.stopEvent();}};this.el.on("keypress",B,this);},validateValue:function(A){if(!Roo.form.NumberField.superclass.validateValue.call(this,A)){return false;}if(A.length<1){return true;}var B=this.parseValue(A);
if(isNaN(B)){this.markInvalid(String.format(this.nanText,A));return false;}if(Bthis.maxValue){this.markInvalid(String.format(this.maxText,this.maxValue));return false;
-}return true;},getValue:function(){return this.fixPrecision(this.parseValue(Roo.form.NumberField.superclass.getValue.call(this)));},parseValue:function(A){A=parseFloat(String(A).replace(this.decimalSeparator,".").replace(this.thousandSeparator,''));return isNaN(A)?'':A;
-},fixPrecision:function(A){var B=isNaN(A);if(!this.allowDecimals||this.decimalPrecision==-1||B||!A){return B?'':A;}return parseFloat(A).toFixed(this.decimalPrecision);},setValue:function(v){v=this.fixPrecision(v);if(this.thousandSeparator!=''){}Roo.form.NumberField.superclass.setValue.call(this,String(v).replace(".",this.decimalSeparator));
-},decimalPrecisionFcn:function(v){return Math.floor(v);},beforeBlur:function(){var v=this.parseValue(this.getRawValue());if(v){this.setValue(v);}}});
+}return true;},getValue:function(){return this.fixPrecision(this.parseValue(Roo.form.NumberField.superclass.getValue.call(this)));},parseValue:function(A){A=parseFloat(String(A).replace(this.decimalSeparator,".").split(this.thousandSeparator).join(''));return isNaN(A)?'':A;
+},fixPrecision:function(A){var B=isNaN(A);if(!this.allowDecimals||this.decimalPrecision==-1||B||!A){return B?'':A;}return parseFloat(A).toFixed(this.decimalPrecision);},setValue:function(v){v=this.fixPrecision(v);if(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){this.hiddenField.value=v?this.parseValue(v):'';}},decimalPrecisionFcn:function(v){return Math.floor(v);},beforeBlur:function(){var v=this.parseValue(this.getRawValue());
+if(v){this.setValue(v);}}});
// Roo/form/DateField.js
Roo.form.DateField=function(A){Roo.form.DateField.superclass.constructor.call(this,A);this.addEvents({'select':true});if(typeof this.minValue=="string"){this.minValue=this.parseDate(this.minValue);}if(typeof this.maxValue=="string"){this.maxValue=this.parseDate(this.maxValue);
}this.ddMatch=null;if(this.disabledDates){var dd=this.disabledDates;var re="(?:";for(var i=0;i