I'm following the JSFiddle given in this thread as the solution to loading jQuery UI AutoComplete from a simple Array of Objects:
The filtering is broken here. There are 2 data rows with a First_Name string, "Will" and "Willem", but if you type anything else e.g. "WA" you still get the full selection of 2 items, where there should be none.
var data = [
{
"id": 1,
"first_name": "Will",
"last_name": "Smith",
"created_at": "2015-01-27T13:09:20.243Z",
"updated_at": "2015-01-27T13:09:20.243Z"
},
{
"id": 2,
"first_name": "Willem",
"last_name": "Dafoe",
"created_at": "2015-01-27T13:17:23.479Z",
"updated_at": "2015-01-27T13:17:23.479Z"
}
];
$('#search').autocomplete({
// This shows the min length of charcters that must be typed before the autocomplete looks for a match.
minLength: 2,
source: function (request, response) {
response($.map(data, function (value, key) {
return {
label: value.first_name,
value: value.id
}
}));
},
focus: function(event, ui) {
$('#search').val(ui.item.first_name);
return false;
},
// Once a value in the drop down list is selected, do the following:
select: function(event, ui) {
// place the person.given_name value into the textfield called 'select_origin'...
$('#search').val(ui.item.first_name);
// and place the person.id into the hidden textfield called 'link_origin_id'.
$('#link_origin_id').val(ui.item.id);
return false;
}
$.ui.autocomplete.filter()Example: jqueryui.com/autocomplete/#multiple