Angular Kendo autocomplete Toggle not working

1 Answer 55 Views
AutoComplete
Acshaya
Top achievements
Rank 1
Acshaya asked on 08 Aug 2023, 11:10 AM
I have a Angular form which contains two autocomplete fields. Both share same reference and call same function. autocomplete.toggle(false) is working for first field but not for the second one.

1 Answer, 1 is accepted

Sort by
0
Hetali
Telerik team
answered on 08 Aug 2023, 07:10 PM

Hello Acshaya,

Thank you for reaching out.

Yes, you can use same reference in different elements, but when you fetch it you will only get the first reference. In order to fetch all the references, use the ViewChildren decorator as seen below:

<button kendoButton (click)="toggle()">Toggle!</button>

<kendo-autocomplete #autocomplete [data]="areaList"> 
</kendo-autocomplete> ;

<kendo-autocomplete #autocomplete [data]="areaList"> 
</kendo-autocomplete>
@ViewChildren('autocomplete') public autocomplete;

public
toggle() { this.autocomplete._results.forEach((dropdown) => { dropdown.toggle(); }); }


In this StackBlitz example, the toggle method is applied to both the Kendo UI AutoComplete components with the same template reference variable.

I hope this helps. Please let me know if I can further assist you.

Regards,
Hetali
Progress Telerik

Stay tuned by visiting our public roadmap and feedback portal pages! Or perhaps, if you are new to our Kendo family, check out our getting started resources
Tags
AutoComplete
Asked by
Acshaya
Top achievements
Rank 1
Answers by
Hetali
Telerik team
Share this question
or