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

Autocomplete single selection

3 Answers 583 Views
AutoComplete
This is a migrated thread and some comments may be shown as answers.
Yoly
Top achievements
Rank 2
Yoly asked on 19 Apr 2016, 02:06 AM

I am using Autocomplete in angular, and I see that I get an array bound to the k-ng-model. 

Here is an example that shows the behavior.

http://dojo.telerik.com/uzefE

Is there a way to get the autocomplete to bind to a single object instead of an array?

Thank you

3 Answers, 1 is accepted

Sort by
0
Dimiter Topalov
Telerik team
answered on 21 Apr 2016, 07:12 AM
Hi Yolanda,

The AutoComplete widget allows multiple selection, hence the returned value should be array of either objects or primitive values. We treat the single selection is a special case of the multiple selection. That is why the returned value is array of single object.

Assuming a single selection, you can access it by index [0]:

<input kendo-auto-complete k-ng-model="country" k-data-source="countryNames" k-options="acOptions" style="width: 400px" />
<p>Your selection: {{ country[0] }}</p>

You can also get the dataTextField only by setting valuePrimitive to true.

I hope this helps.

Regards,
Dimiter Topalov
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Anand
Top achievements
Rank 1
answered on 22 Sep 2016, 06:18 AM

Hello Dimiter,
I'm facing a similar issue in our project.

For selecting customer in one of our form I'm using auto complete. User can type customer name then the auto complete control will list all customers starts with that name. We have 2 customers with exact same name (2 branches of same company); I differentiate those items by additional information like customer code, city etc in their template. The attached screenshot will better explain the issue.

When user select any one item, k-ng-model returns array of 2 objects. Now how can I identify which item user actually selected ?

0
Dimiter Topalov
Telerik team
answered on 26 Sep 2016, 08:27 AM
Hello Anand,

The Kendo UI AutoComplete is not designed to distinguish between items with same dataTextField, and does not have the concept of dataValueField (however, the currently selected item is available via e.dataItem in the select event handler).

If you have to distinguish between items with same dataTextField, you can use the Kendo UI MultiSelect (that supports dataValueField option) instead:

http://demos.telerik.com/kendo-ui/multiselect/angular

http://docs.telerik.com/kendo-ui/controls/editors/multiselect/overview

I hope this helps.

Regards,
Dimiter Topalov
Telerik by Progress
Get started with Kendo UI in days. Online training courses help you quickly implement components into your apps.
Tags
AutoComplete
Asked by
Yoly
Top achievements
Rank 2
Answers by
Dimiter Topalov
Telerik team
Anand
Top achievements
Rank 1
Share this question
or