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

Autofocus on kendo-autocomplete control

1 Answer 1390 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
rk
Top achievements
Rank 1
rk asked on 09 Jul 2018, 07:16 PM

 Hi,

I have a 'kendo-autocomplete' control on my app. Trying to set auto focus (element highlighted) on page load.  Using native javascript was able to track down the HTML element , but cannot fire 'click' / 'focus' events on them. Can you please help ?

I have seen a jquery post achieving the same , by calling .data('kendo-autocomplete). https://stackoverflow.com/questions/17152915/setting-focus-on-autocomplete-textbox

Here's what I tried ->

1. let searchInput: HTMLElement = document.getElementsByClassName('customClass')[0] as HTMLElement;

     searchInput.click(); //doesn't fire

 

2. Native Angular way -> Doesn't even find the element on DOM.

    <kendo-autocomplete #findMe>

     @ViewChild('findMe') searchInput: ElementRef;

     ngAfterViewInit() {

            this.searchInput.nativeElement.focus();    //searchInput is not defined. 

     }

1 Answer, 1 is accepted

Sort by
0
Svet
Telerik team
answered on 11 Jul 2018, 09:04 AM
Hi Ramakrishna,

Indeed, using custom JavaScript logic we can use the focus method of an HTML element. We can also get a reference to the AutoComplete component via Angular's @ViewChild and call its focus method as well.

Check the following sample plunker demonstrating both approaches:
https://plnkr.co/edit/C7uXYE4rgYZ8xsKN7pJV?p=preview

I hope this helps.

Regards,
Svetlin
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
General Discussions
Asked by
rk
Top achievements
Rank 1
Answers by
Svet
Telerik team
Share this question
or