1

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

Jason
  • 2,455
  • 4
  • 37
  • 48
  • Use `$("#autocomplete").data("kendoAutoComplete").value("Oranges");` – OnaBai May 27 '14 at 18:25
  • Arg, I thought I'd tried that. Must have had something else wrong at the time. Thanks OnaBai! Add your comment as an answer and I'll set it as the Answer. – Jason May 27 '14 at 18:38

1 Answers1

3

Answer from OnaBai

$("#autocomplete").data("kendoAutoComplete").value("Oranges");
RayLoveless
  • 19,880
  • 21
  • 76
  • 94
  • The `value()` method sets the string value of the widget, not the dataItem. And it's a description field rather than an ID. Basically, the AutoComplete widget lets you pick one item from an array of strings. What you pass to `value()` should be one of those strings. – Suncat2000 Feb 19 '19 at 15:55