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

Is there a way to set the keyboard focus to the DropDownList?

2 Answers 195 Views
DropDownList
This is a migrated thread and some comments may be shown as answers.
João
Top achievements
Rank 1
João asked on 19 Jan 2012, 04:27 AM
I just want to set the focus at the DropDown list of items, so if the user presses the up or down arrow in the keyboard, the selected item changes.

The only way I can do this is by clicking in the DropDownList arrow. How can I do the same with code?

Thanks...

2 Answers, 1 is accepted

Sort by
0
Andrew
Top achievements
Rank 1
answered on 06 Feb 2013, 04:16 PM
I'd love to know too. I've spent two hours trying to work this out. 2 mins in a thick client app. Sometimes I hate the Web!
0
Andrew
Top achievements
Rank 1
answered on 06 Feb 2013, 04:46 PM
OK, finally got it working. In the end the code posted elsewhere is OK - my problem was worsened by a race condition. I set the focus to the first dropdown in a popup dialog. Because the activation of a kendoWindow was immediate on the page load, there was a race condition. When I switched it to being triggered by a user action (as it should be in the final solution) it works.

FYI:

The window was opened with:

    var win = $('#copyDownWindow').data('kendoWindow');
    win.center();
    win.open();

and then within the activate event the first dropdown was selected.

 $("#copyDownWindow").kendoWindow({
        actions: ["Close"],
        draggable: true,
        height: "300px",
        modal: true,
        resizable: true,
        title: "Copy Down Properties",
        width: "500px",
        visible: false,
        activate: function () {
            var x = $('#copyDownWindow span.k-widget:first');
            if (x) {
                x.focus();
            }
        }
    });

This works. It just won't work if the visible=true thus displaying the window immediately on startup.
Tags
DropDownList
Asked by
João
Top achievements
Rank 1
Answers by
Andrew
Top achievements
Rank 1
Share this question
or