PDA

View Full Version : Numberfields



MutexSystems
6 Feb 2013, 4:59 AM
Hello,
How can I show two digits in a numberfield?
Instead of showing 0-9, I want 00, 01, 02, ..09

Best Regards!

sdt6585
6 Feb 2013, 6:30 AM
You might have to extend the spinner to get that to work. Something like this:



Ext.define('Ext.ux.CustomSpinner', {
extend: 'Ext.form.field.Spinner',
alias: 'widget.customspinner',

constructor: function () {
this.callParent(arguments);

this.on("blur", function () {
if (!this.readOnly) {
var val = parseInt(this.getValue(), 10)||0;
var sign = (val < 0 ? "-" : "");
val = Math.abs(val);
for (var i = val.toString().length; i < this.pad; i++) {
val = "0" + val;
}
this.setValue(sign + val);
}
}, this);
},

pad: 2,

onSpinUp: function() {
var me = this;
if (!me.readOnly) {
var val = parseInt(me.getValue(), 10)||0;
val++;
var sign = (val < 0 ? "-" : "");
val = Math.abs(val);
for (var i = val.toString().length; i < this.pad; i++) {
val = "0" + val;
}
me.setValue(sign + val);
}
},

onSpinDown: function() {
var val, me = this;
if (!me.readOnly) {
var val = parseInt(me.getValue(), 10)||0;
val--;
var sign = (val < 0 ? "-" : "");
val = Math.abs(val);
for (var i = val.toString().length; i < this.pad; i++) {
val = "0" + val;
}
me.setValue(sign + val);
}
},
stripCharsRe: /[^0-9]/g
});

Ext.create('Ext.form.FormPanel', {
title: 'Form with SpinnerField',
bodyPadding: 5,
width: 350,
renderTo: Ext.getBody(),
items:[{
xtype: 'customspinner',
fieldLabel: 'How Much Beer?',
pad: 5
}]
});

MutexSystems
6 Feb 2013, 6:48 AM
Great, thanks. I will try it.