Autocomplete with k-ng-model and dataValueField issues

5 posts, 1 answers
  1. SharpLogic
    SharpLogic avatar
    15 posts
    Member since:
    Feb 2014

    Posted 12 Feb 2015 Link to this post

    Two issues I'm having using the AutoComplete control with Angular...

    I'm trying to bind the object/dataItem of the selected item in an autocomplete control to an object on my controller.

    <input type="text"  id="acAccount" ng-model="vm.Deal.AccountId" k-ng-model="vm.Account"<br>                                       kendo-auto-complete="acAccount" k-options="vm.accountAutoComplete"  />

    It works, although the object vm.Account is always an array with a single item?  How can I make this simply be the selected item?

    It works great with the DropDownList.

    2nd problem is the value is being bound to the dataTextField, not the dataValueField.
    I can look in chrome console and go

    $scope.acAccount.options.dataValueField

     and I have the correct field name but when I go

    $scope.acAccount.value()

    I have the value from the dataTextField.  And that is of course what is stored in vm.Deal.AccountId

    Any ideas on either of those.  The array I can work with, although not desirable I can use the on-change/select event and handle that myself...but the value() is a touch strange.  Well, i guess I can also deal with that in the on-change!!!

    Still...it'd be nice if someone could see the errors of my ways!

    Thx
    Steve
  2. Answer
    Georgi Krustev
    Admin
    Georgi Krustev avatar
    3706 posts

    Posted 16 Feb 2015 Link to this post

    Hello Steven,

    The AutoComplete widget is designed to be a simple (data bound) suggestion box. It supports only a dataTextField option and hence it will not work like DropDownList/ComboBox widget. If you would like to work with whole objects, then there should be no problems. Here is a Dojo demo that demonstrates this case. If you, however, would like to work primitive values, then ComboBox/DropDownList widgets will be more suitable for you. Please check this documentation for more details about primitive values.

    Regards,
    Georgi Krustev
    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. SharpLogic
    SharpLogic avatar
    15 posts
    Member since:
    Feb 2014

    Posted 21 Feb 2015 in reply to Georgi Krustev Link to this post

    Thanks.  OK, makes sense.

    Although the item bound in your demo "country" is also an array with a single item.  Can you select multiple in a autocomplete...well it doesn't matter.

    I've actually been looking at the ComboBox and use the dropdown else where...

    To be honest the ComboBox seems riddled with oddities.  Even in you demos...but I'll put another post up for that!
  5. Garret
    Garret avatar
    1 posts
    Member since:
    Apr 2015

    Posted 01 Apr 2015 in reply to Georgi Krustev Link to this post

    I'm with SharpLogic, I don't understand why the the value is an array. In your dojo demo, if a user selects albania, the bound object has value [{"name":"Albania"}]. Shouldn't it just be {"name":"Albania"}. 

    The expected behavior when the dataSource is an array of FooBar objects is that selecting one will result in the bound object being an instance of FooBar, not an array with 1 FooBar item in it, right?

    Or, as SharpLogic said, I'd love it if someone could point out the errors in my ways.
  6. Georgi Krustev
    Admin
    Georgi Krustev avatar
    3706 posts

    Posted 03 Apr 2015 Link to this post

    Hello,

    The AutoComplete widget allows multiple selection (controlled by placeholder option), 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.

    Regards,
    Georgi Krustev
    Telerik
     
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
     
Back to Top
Kendo UI is VS 2017 Ready