PDA

View Full Version : Trying to extend field



ludo
21 Jan 2011, 7:23 AM
Hello,
I'm trying to extend NumberField to AmountField, but how to do that ?



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

Ext.ux.form.AmountField = Ext.extend(Ext.form.NumberField, {
validationEvent:'keyup',

decimalSeparator: '.',
decimalPrecision: 2,

allowNegative : false,

maxValue : 999999.99,
maxText : "La valeur de ce champ dépasse le montant maximal autorisé.",
autoCreate: {tag: 'input', type: 'text', autocomplete: 'off', maxlength: '9'},

setValue : function(v){
v = isNaN(v) ? '' : this.fixPrecision(String(v).replace(".", this.decimalSeparator));
return Ext.form.NumberField.superclass.setValue.call(this, v);
},

fixPrecision : function(value){
var nan = isNaN(value);
if(!this.allowDecimals || this.decimalPrecision == -1 || nan || !value){
return nan ? '' : value;
}
return parseFloat(value).toFixed(this.decimalPrecision);
}
});

Ext.reg('amountfield', Ext.ux.form.AmountField);

Now, my first simple form :

var testForm = new Ext.form.FormPanel({
width: 250,
height: 100,
items: [
{ xtype : 'numberfield', fieldLabel: 'A classic NumberField' },
{ xtype : 'amountfield', fieldLabel: 'My AmountField' }
]
});

24406
Ok, When I enter a value, the field behavior is correct.

But, if I put several "AmountField" like this:

var testForm = new Ext.form.FormPanel({
width: 250,
height: 100,
items: [
{ xtype : 'numberfield', fieldLabel: 'A classic NumberField' },
{ xtype : 'amountfield', fieldLabel: 'My AmountField' },
{ xtype : 'amountfield', fieldLabel: 'Second AmountField' }
]
});

24407
Only the last field is ok, and I not understand why, for sure, I missed something, but what ?...

I need your help,
Thanks in advance,