Autocomplete pre-selected value


#1

I’m using Autocomplete with an array of objects as data source, ex:
[{id: 1, name: "Mike"}, {id: 2, name: "Joe"}, ...]

I need to set a default value, so i tried using the ‘value’ property on create (assuming it’s based on valueProperty… but i couldn’t find anything specific in documentation)

app.autocomplete.create({
      inputEl: '#autocomplete-dropdown',
      openIn: 'dropdown',
      value: [1], //selected item's ID
      valueProperty: 'id',
      textProperty: 'name',
      source: function(query, render) {
        render(users);
      }
    });

but it doesn’t works. any help? thanks

fiddle: https://jsfiddle.net/skw2erhL/1/


#2

Dropdown autocomplete is linked to input, so just required value on input element:

$('#autocomplete-dropdown').val('Mike');