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

How to focus AutoCompleteBox racInput?

3 Answers 50 Views
AutoCompleteBox
This is a migrated thread and some comments may be shown as answers.
Yan Moura
Top achievements
Rank 1
Veteran
Iron
Yan Moura asked on 20 Jan 2021, 06:04 PM

I am trying to focus the AutoCompleteBox racInput but got no success. I tried this:

function pageLoaded() {
            var radInput = $find("<%= RadAutoCompleteBox1.ClientID %>");
            radInput.focus();
            //console.log(document.getElementById('RadAutoCompleteBox1'));
        }

<body onload="pageLoaded()">

Any idea?

3 Answers, 1 is accepted

Sort by
0
Vessy
Telerik team
answered on 21 Jan 2021, 03:01 PM

Hi Yan,

The client-side object of RadAutoComplete control does not expose a focus() method. If you want to call the focus() of its input element, you will first need to access the input using the get_inputElement() method.

The client-side API of the control can be found here:

https://docs.telerik.com/devtools/aspnet-ajax/api/client/Telerik.Web.UI.RadAutoCompleteBox

I will also advice to do that in the client-side Load handler of the control in order to ensure that the client-object is loaded and accessible:

        <telerik:RadAutoCompleteBox RenderMode="Lightweight" runat="server" ID="RadAutoCompleteBox1"
            EmptyMessage="Please type here" AllowCustomEntry="false"
            DataSourceID="SqlDataSource1" DataTextField="FirstName"
            OnClientLoad="onClientLoad"
            InputType="Text" Width="350" DropDownWidth="150px">
        </telerik:RadAutoCompleteBox>

        <script>
            function onClientLoad(autoComplete, args) {
                var radInput = autoComplete.get_inputElement();
                radInput.focus();
            }
        </script>

Regards,
Vessy
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

0
Yan Moura
Top achievements
Rank 1
Veteran
Iron
answered on 21 Jan 2021, 03:21 PM

Thank you Vessy!

In fact I realized that it WAS getting the focus but due to an issue in the EmptyMessage feature I was not seeing it.

0
Vessy
Telerik team
answered on 22 Jan 2021, 05:31 PM

Hi,

You are welcome, Yan :)

Regards,
Vessy
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Tags
AutoCompleteBox
Asked by
Yan Moura
Top achievements
Rank 1
Veteran
Iron
Answers by
Vessy
Telerik team
Yan Moura
Top achievements
Rank 1
Veteran
Iron
Share this question
or