PDA

View Full Version : How to install key handler on Panel?



dbassett74
12 Oct 2009, 11:35 AM
My approach is to build everything in Panels and then use those panels where they're needed, such as inside a window. I need to implement a "defaultButton" type handler on the Panel so that no matter what element currently has the focus in a Panel (assuming that element doesn't do anything with the Enter key already), the Panel will instead get the event and do something with it.

Is this easily accomplished? For example:

Panel1
TextField1
TextField2

User is currently inside TextField1 and hits Enter, I want Panel1 to grab this event and do something with it. Is there a way to do this without having to put a listener on each TextField and specifying enableKeyEvents??

wuschba
12 Oct 2009, 11:38 AM
Inside Panel1, you can just use:
this.getEl().addKeyListener(Ext.EventObject.ENTER, this.onEnter, this);

dbassett74
12 Oct 2009, 11:50 AM
Marvelous!