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
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
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 ?
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