vendredi 13 février 2015

[5.0] My extension to have formatted and leading-zeros-enabled number field

I want to share with you simple class extended from numberfield to enable zeroes-leading and custom formatting:

afbdc28899d2e08b17beabade5b255c4.png


Code:



/**
* @author Adam Borowski
*/
Ext.define('cas.helper.component.FormattedNumberField', {
extend: 'Ext.form.field.Number',
xtype: 'formattednumberfield',
config: {format: null, leadingZeros: 2},
constructor: function (config) { this.callParent(arguments);
this.initConfig(config);
var me = this;
this.on('blur', function () {
this.setRawValue(this.getRawValue());
});
},
valueToRaw: function (value) {
var s = this.parseValue(value);
if (this.getFormat() != null) {
s = Ext.util.Format.number(s, this.getFormat());
}
if (this.getLeadingZeros()) {
s = Ext.util.Format.leftPad(s, this.getLeadingZeros(), '0');
}
return s;
}
});

How to check that user is already typing values into field so we can't affect the input



[5.0] My extension to have formatted and leading-zeros-enabled number field

Aucun commentaire:

Enregistrer un commentaire