View Full Version : Number Field validation

11 Jul 2011, 7:05 AM
I am building a banking app using Sencha Touch. I have a Number Field on the screen that allows the user to type in a amount. I see no way to force numeric entry only, or to apply a mask to the box so that they type in numbers and it fills in from right to left auto inserting decimal. I see I can work with the keyup event. However keyup is too late. I need access to a keydown event. I'm not sure why Sencha chose to not include the keydown event in their Number Field. Does anyone know how this can be accomplished?



11 Jul 2011, 11:58 AM
accountToAmountBox = new Ext.form.Number({
inputType: 'number',
cls: 'accountToAmountBox',
initEvents: function () {
var keyDown = function (e) {
if (notNumber(e.browserEvent.keyCode)) {
this.el.on("keydown", keyDown, this);
label: 'Amount', labelWidth: '100%', labelAlign: 'top', required: 'true'
});The code inside my keydown function could be whatever you like. The point is this causes that event to fire and your function to get called.