Autocomplete single selection

4 posts, 0 answers
  1. yceron
    yceron avatar
    21 posts
    Member since:
    Apr 2007

    Posted 18 Apr Link to this post

    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

  2. Dimiter Topalov
    Admin
    Dimiter Topalov avatar
    355 posts

    Posted 21 Apr Link to this post

    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!
  3. Kendo UI is VS 2017 Ready
  4. Anand
    Anand avatar
    1 posts
    Member since:
    Oct 2015

    Posted 22 Sep in reply to Dimiter Topalov Link to this post

    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 ?

  5. Dimiter Topalov
    Admin
    Dimiter Topalov avatar
    355 posts

    Posted 26 Sep Link to this post

    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.
Back to Top
Kendo UI is VS 2017 Ready