This is a migrated thread and some comments may be shown as answers.

Node keypress event

1 Answer 197 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Irit
Top achievements
Rank 1
Irit asked on 03 Feb 2013, 04:31 PM
Hey,

I'm trying to find a way to bind an enter keypress event to some function, so that using only the keyboard, when a user presses enter on some node, it will lead to some action.

I wonder what is the correct way to do that.
I have a complicated template for each node, and I tried to bind the keydown event to a class I have in each node, but that didn't work (it did work for me with the click event though...)

Any advice?

Thanks,

1 Answer, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 05 Feb 2013, 08:12 PM
Hello,

In order to capture keyboard events the element that you are binding to should have tabindex. The TreeView wrapper element by default has tabindex so you could use it. To determine the focused element in the handler, you can search for the "k-state-focused" class e.g.

$("#treeview").on("keydown", function (e) {
    if (e.keyCode == 13) {
        var focusedItem = $(this).find(".k-item:has( > div > .k-state-focused)");
        //your logic
    }
});
Regards,
Daniel
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
TreeView
Asked by
Irit
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Share this question
or