PDA

View Full Version : numberfield comma separator



genTaliaru
10 Dec 2009, 5:43 AM
How to set to ext numberfield comma separator dot and comma.
I want it to both works. Can somebody tells me how?

Condor
10 Dec 2009, 7:03 AM
You would have to patch NumberField, e.g.

Ext.override(Ext.form.NumberField, {
decimalSeparators: '.,',
initEvents : function(){
var allowed = this.baseChars + '';
if (this.allowDecimals) {
allowed += this.decimalSeparators;
}
if (this.allowNegative) {
allowed += '-';
}
this.maskRe = new RegExp('[' + Ext.escapeRe(allowed) + ']');
this.decimalSeparatorRe = new RegExp('[' + Ext.escapeRe(this.decimalSeparators) + ']', 'g');
Ext.form.NumberField.superclass.initEvents.call(this);
},
validateValue : function(value){
if(!Ext.form.NumberField.superclass.validateValue.call(this, value)){
return false;
}
if(value.length < 1){
return true;
}
value = String(value).replace(this.decimalSeparatorRe, ".");
if(isNaN(value)){
this.markInvalid(String.format(this.nanText, value));
return false;
}
var num = this.parseValue(value);
if(num < this.minValue){
this.markInvalid(String.format(this.minText, this.minValue));
return false;
}
if(num > this.maxValue){
this.markInvalid(String.format(this.maxText, this.maxValue));
return false;
}
return true;
},
setValue : function(v){
v = Ext.isNumber(v) ? v : parseFloat(String(v).replace(this.decimalSeparatorRe, "."));
v = isNaN(v) ? '' : String(v).replace(".", this.decimalSeparator);
return Ext.form.NumberField.superclass.setValue.call(this, v);
},
parseValue : function(value){
value = parseFloat(String(value).replace(this.decimalSeparatorRe, "."));
return isNaN(value) ? '' : value;
}
});

genTaliaru
10 Dec 2009, 10:50 PM
Thanks a lot, its works