PDA

View Full Version : KeyListener, Tabpanel and rest of the site



wannabe
15 Sep 2006, 5:01 AM
I've trying to mess with Tabpanel and integrating it into my site. So far so good, but it'd be really nice (IMHO) to add a KeyListener to it, so when I press a certain key, the right tab will be displayed (instead of clicking on the tab). So far so good too ...

But when I'm in a text input field, and use that key too, the right tab will be opened as well. How do I prevent the KeyListener to work, only when I'm not in some input field? Any pointers?

jack.slocum
15 Sep 2006, 10:43 AM
The grid uses javascript and the mouse down event to disable text selections within it. When the grid has a textfield or textarea I need to allow text selections. This is similar to your problem. When the event bubbles, you need to know if you should handle it or not.

I'm not sure if this is the best solution but it works for me and allows me to make the field names configurable:


function yourKeyDownHandler(e){
// this pattern should be defined somewhere else and reused for each call
var allowPattern = /INPUT|TEXTAREA/i;
var target = YAHOO.util.Event.getTarget(e);
if(target && !allowPattern.test(target.tagName)){
// do your keydown stuff
}
}


You could also attach a key listener to every textfield and stopPropagation on each of them, but IMO that wouldn't be better it would be worse.

Jack