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

Remove focus from AutoCompleteBox after selection?

2 Answers 1590 Views
AutoCompleteBox for HTML
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Nikhil
Top achievements
Rank 1
Nikhil asked on 10 Dec 2013, 04:15 PM
Hello,

I see the autocomplete.focus() method to put the focus on the autocompletebox, but I can't find a way to remove focus from the autocompletebox. After a user selects an item from the dropdown list, the cursor still remains in the autocompletebox, blinking. I expected something like autocomplete.blur() to exists, but haven't found anything similar. Win 8 doesn't seem to think anything is in focus, so document.activeElement.blur() doesn't work, either. autocomplete.close() just removes the dropdown list. Is there anything built in to remove focus or reset the autocomplete box in order to remove the focus?

Thanks,
Nikhil

2 Answers, 1 is accepted

Sort by
0
Accepted
Martin Yankov
Telerik team
answered on 11 Dec 2013, 09:30 AM
Hi Nikhil,

In order to force the RadAutoCompleteBox input element to lose focus in the event handler, you need to apply the blur() function in a timeout. Even a minimal timeout will be enough. Here is an example code sample:
autoCompleteBox.addEventListener("select", function (e) {
    setTimeout(function () {
        document.activeElement.blur();
    }, 15);
});

I hope this information is useful. In case of any further questions or problems do not hesitate to ask.

Regards,
Martin Yankov
Telerik

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Nikhil
Top achievements
Rank 1
answered on 11 Dec 2013, 04:20 PM
Ah, interesting. Works great, thank you!

Nikhil
Tags
AutoCompleteBox for HTML
Asked by
Nikhil
Top achievements
Rank 1
Answers by
Martin Yankov
Telerik team
Nikhil
Top achievements
Rank 1
Share this question
or