Andy T
Andy T

Reputation: 9881

Setting focus() on autocomplete textbox

I am trying to set the cursor on the textbox that has been set to a kendoAutoComplete, but the cursor does not show.

Using Kendo's AutoComplete basic demo I am running the following code in the Chrome Developer console, but the cursor is not showing.

$('#countries').focus()

When the code is run, I do see that the span around the input box does get the 'k-state-focused' class which changes the border color to gray, but that's all it does.

From what I can tell, the 'k-state-focused' css class doesn't hide the cursor. So not sure if Kendo is somehow intercepting the focus in JavaScript and not setting it, or because the textbox has a span around it, the focus is being hidden.

Upvotes: 1

Views: 6208

Answers (2)

Mominator
Mominator

Reputation: 47

The first answer didn't work for me. It could be because I'm using UI for ASP.NET Core, but this solution did work:

$(document).ready(function () {
    setTimeout(function () {
        $("#myInputId").focus();
    });
});

This is the explanation from Telerik - "The AutoComplete widget is designed to persist the focus of the input when popup element is clicked. The select is raised between of the open->click->close chain and that is why we will need to use setTimeout function to focus other input."

Upvotes: 2

OnaBai
OnaBai

Reputation: 40887

Instead of $('#countries').focus() do $('#countries').data("kendoAutoComplete").focus().

Due to Kendo UI decorations around HTML elements you should use AutoComplete focus.

Upvotes: 6

Related Questions