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

programmatic Search then Select

1 Answer 295 Views
AutoComplete
This is a migrated thread and some comments may be shown as answers.
Richard
Top achievements
Rank 1
Richard asked on 08 Oct 2017, 07:20 PM

At the first rendering of a page I would like to specify and process the selection of a default autocomplete value.  I thought this code might work, it doesn't:

$(document).ready(function () {
    var ac = $("#autoComplete").data("kendoAutoComplete");
    var target = "170035";
    ac.search(target)
        .then(ac.select(target))
        .then(ac.trigger("change"))
     ;
})

AutoComplete search() does not return a promise. A promise would be needed for the .then() chaining I want to do.  For comparison, DataSource read() does return a promise and can be part of a chain.

Q: Can you suggest a different approach for search and select ?

Thanks, Richard

 

1 Answer, 1 is accepted

Sort by
0
Nencho
Telerik team
answered on 11 Oct 2017, 06:46 AM
Hello Richard,

Indeed, the select method does not inherit the promise interface. This is why, you would need to use the $.when, in order to achieve the desired functionality:

  var target = "170035";
  var ac = $("#autocomplete").data("kendoAutoComplete");
  
$.when(ac.search("170035"))
     .then(ac.select(ac.ul.children().eq(0)))
     .then(ac.trigger("change"))

Here is a dojo example regarding the above implementation: https://dojo.telerik.com/isASA/6

Or you can use the approach, demonstrated in our documentation article below:

https://docs.telerik.com/kendo-ui/api/javascript/ui/autocomplete#methods-select

Regards,
Nencho
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
AutoComplete
Asked by
Richard
Top achievements
Rank 1
Answers by
Nencho
Telerik team
Share this question
or