PDA

View Full Version : How to detect enter key in formPanel



gut
31 Aug 2011, 8:45 PM
Could anyone tell me how to detect when enter key is pressed in a formPanel. Looks like a simple task, but I have no clue.

Please help.

mitchellsimoens
1 Sep 2011, 5:03 AM
Should be able to add a listener for 'specialkey' and the second argument is an EventObject. You should be able to check to see if the key is e.ENTER.

http://docs.sencha.com/ext-js/4-0/#!/api/Ext.form.field.Text-event-specialkey

There is an example how to do just that.

If you wanted it on the Ext.form.Panel iteself you can do something like this:


form.mon(form.el, {
keypress : function(e, t, opts) {
if (e.getKey() == e.ENTER) {....}
}
});

You can use keyup or keydown if you don't want keypress.

gut
2 Sep 2011, 12:08 AM
PM
mitchellsimoens,

Thank you very much for your quick reply. Your suggestion does just what I need.

Cheers!