nsr.cls.MoneyField

Ext.ns("nsr.cls");
nsr.cls.MoneyField = Ext.extend(Ext.form.TextField, {
	fieldFormat: '0/i'
	,value: 0
	,constructor:function(config) {
		config = config || {};
		nsr.cls.MoneyField.superclass.constructor.call(this, config);
	}
	,initComponent:function() {
		var config = {};
		this.buildConfig(config);
		Ext.apply(this, Ext.apply(this.initialConfig, config));
        nsr.cls.MoneyField.superclass.initComponent.apply(this, arguments);
	}
	,buildConfig: function(config){
		config.maskRe 			= /[0-9\,]/;
		config.decimalSeparator	= ',';
	}
	,onBlur : function(){
		nsr.cls.MoneyField.superclass.onBlur.call(this);
		var value = this.el.dom.value;
        value = value.replace(/\,/, '.');
        value = Ext.util.Format.number(value, '0.' + this.fieldFormat);
        this.el.dom.value = value==''?0:value;
	}
	,onFocus : function(){
		nsr.cls.MoneyField.superclass.onFocus.call(this);
		var value = this.el.dom.value;
        value = value.replace(/[^0-9\,]+/g,'');
        value = value.replace(/\,/, '.');
        value = Number(value);
        value = Ext.util.Format.number(value, this.fieldFormat);
        this.el.dom.value = value;
	}
	,setValue : function(v){
		nsr.cls.MoneyField.superclass.setValue.call(this, v);
		var value = v;
        value = Ext.util.Format.number(value, '0.' + this.fieldFormat);
        this.el.dom.value = value==''?0:value;
    }
    ,getValue : function(){
    	var v = this.el.getValue();
        if(v === this.emptyText || v === undefined){
            v = '';
        }
        v = v.replace(/[^0-9\,]+/g,'');
        v = v.replace(/\,/, '.');
        v = Number(v);
        return v;
    }

});
Ext.reg('moneyfield', nsr.cls.MoneyField);

Contoh penggunaan:

xtype: 'moneyfield',
fieldLabel: 'Kurs',
name: 'Kurs',
maxLength: 50,
disabled: true,
allowBlank:false,
anchor:'-5',
fieldFormat: '0,00/i',
ref: '../../txtKursSumber'