PDA

View Full Version : CurrencyField POST Value



nkezhaya
18 Feb 2011, 12:30 PM
Pretty self-explanatory. Everything works, but when I submit the form, it sends the formatted value. _onBlur() isn't working properly.


Ext.ns('Ext.ux.form');

Ext.ux.form.CurrencyField = Ext.extend(Ext.form.TextField, {
allowCents : true

,rawFormat : function(v) {
var t = String(v).replace(/[^\d\.]/g, '');
return parseFloat(t);
}

,formatter : function(v) {
v = this.rawFormat(v);

if(v == null) {
return '';
} else if(isNaN(v)) {
return '$0.00';
} else {
var f = Ext.util.Format.usMoney(this.rawFormat(v));
return this.allowCents ? f : f.substr(0, f.length - 3);
}
}

,getValue : function() {
return this.rawFormat(this.el.dom.value);
}

,setValue : function(v) {
v = this.formatter(v);
return Ext.form.CurrencyField.superclass.setValue.call(this, v);
}

,initEvents : function() {
this.on('blur', this._onBlur);
Ext.form.CurrencyField.superclass.initEvents.call(this);
}

,_onBlur : function() {
this.value = this.getValue();
this.setValue(this.value);
}
});

Ext.reg('currencyfield', Ext.ux.form.CurrencyField);
Ext.form.CurrencyField = Ext.ux.form.CurrencyField;