Reputation: 39
I've been banging my head against the wall for days trying to get a KeyPress or a KeyDown event to fire on a Sencha Touch textfield.
I'm trying to accomplish two things: 1) Limit the max length to 3 and 2) Ensure that the user is entering only numbers (no letters or special chars)
Is there no way using Javascript to attach these events? I'm using Sencha 2.3.1
Update: I've tried using numberfield and also using maxLength...neither work.
var numberfield =
{
xtype: 'numberfield',
value: textValue,
readOnly: true,
cls: 'opBuyoffPartialCell',
inputCls: 'opBuyoffCenterText',
maxLength: 3,
enforceMaxLength: 3
};
Upvotes: 0
Views: 92
Reputation: 20224
As @MonicaOlejniczak wrote, use a numberfield.
If you don't want to use a numberfield, at least have a look at its code and find that Sencha uses
this.getComponent().input.dom.setAttribute("type", "number");
to ensure that the user can only input numbers. That way, the "number" ,,,
, which your code would allow, will also be taken care of.
To ensure a maxLength
, sencha already has maxLength
config which is available on both the numberfield and the textfield.
Upvotes: 0