How to set the value of a Kendo AutoComplete control to a javascript object?

Jason picture Jason · May 27, 2014 · Viewed 7.5k times · Source

I have a KendoUI AutoComplete control bound to a list of objects. What I can't figure out is how to set the selected value of the AutoComplete from javascript. For example:

<input id="autocomplete" />
<script>
  $("#autocomplete").kendoAutoComplete({
    dataTextField: "Name",
    dataSource: [ 
      { id: 1, Name: "Apples" }, 
      { id: 2, Name: "Oranges" }, 
      { id: 3, Name: "Carrots" } ]
  });

  $("#autocomplete").data("kendoAutoComplete").value({ id: 2, Name: "Oranges" });
</script>

This just results in the AutoComplete control showing [object Object]. A jsBin of the problem is available here: jsBin

Any suggestions? Jason

Answer

RayLoveless picture RayLoveless · Jun 17, 2016

Answer from OnaBai

$("#autocomplete").data("kendoAutoComplete").value("Oranges");