PDA

View Full Version : kepress event to return false



jimtyp
21 Dec 2009, 4:10 PM
In javascript if I have an input field with an onkeypress event I can return false and the character typed will not be entered into the field.

I tried this in EXTJS using a listener for kepress, but returning false from the function still allows the character to go through, and setting the returnValue of the event doesn't seem to do anything.

Is this a bug or is there another way in EXTJS to do this?

tot2ivn
21 Dec 2009, 7:31 PM
Actually ExtJS can make your life easier using VTypes (http://www.extjs.com/deploy/dev/docs/source/VTypes.html#cls-Ext.form.VTypes). You can use the regex-based mask to filter keystrokes input.

Totti

jimtyp
22 Dec 2009, 8:37 AM
The problem with the vtypes is it still allows the user to type in an invalid character and just shows a message saying not the right format. I'd much prefer to not even allow the invalid character, just like I used to be able to do simply with javascript and the onkeypress event.

tot2ivn
22 Dec 2009, 8:43 AM
Hi jimtyp,

Please read the API carefully, vType has the feature of blocking invalid keystrokes, which means that user cannot even key in invalid chars according to the regex configured.

Totti

jimtyp
22 Dec 2009, 9:04 AM
I've looked at the API and don't see how to filter out keystrokes. I've looked at some examples also and they don't show it either. Can you provide a simple example that won't allow an alpha character to be entered?

jimtyp
22 Dec 2009, 9:23 AM
Ah, never mind, I see it! And it works! Woohoo! THANK YOU!