PDA

View Full Version : Override TreePanel to support onkeyup, onkeydown events



mik001
10 Mar 2011, 6:14 AM
Hi guys,

I'm stuck on overriding the TreePanel to support onkeyup and onkeydown events
on child nodes. I've basically followed the thread post http://www.sencha.com/forum/showthread.php?17532-Add-keydown-keypress-and-keyup-events-to-form-fields that was
basically doing the same for Forms.

So I've added the following:


Ext.override(Ext.tree.TreePanel, {
fireKey : function(e) {
if(((Ext.isIE && e.type == 'keydown') || e.type == 'keypress') && e.isSpecialKey()) {
this.fireEvent('specialkey', this, e);
}
else {
this.fireEvent(e.type, this, e);
}
}
, initEvents : function() {
// this.el.on(Ext.isIE ? "keydown" : "keypress", this.fireKey, this);
this.el.on("focus", this.onFocus, this);
this.el.on("blur", this.onBlur, this);
this.el.on("keydown", this.fireKey, this);
this.el.on("keypress", this.fireKey, this);
this.el.on("keyup", this.fireKey, this);

// reference to original value for reset
this.originalValue = this.getValue();
}
});


I'm not understanding why after adding this cose, all the TreePanels
of my code are just messed up: rendering is completely broken.

Is there any other way to catch onkeyup and onkeydown (basically following
up/down arrow keys while going up/down in the tree nodes) to the TreePanel?

Please let me know
Thanks for your time
mik001

mik001
10 Mar 2011, 6:40 AM
I've also tried a different approach, that I've found later reading the doc.
I've added to my TreePanel definition the following, but without any result again:



keys: [
{ key: Ext.EventObject.UP, fn: function() {
console.log("keyup");
}
},
{ key: Ext.EventObject.DOWN, fn: function() {
console.log("keydown");
}
}
]


This should work, at least as per-doc.

Can someone please explain me what it wrong?

Thanks
mik001