JQuery UI Autocomplete
I'm not going to go deep into explaining how to use Autocomplete as the full documentation for a custom implementation can be found here and for the most part, it works.
The simple trick is to replace .autocomplete("instance") with .data("uiAutocomplete"), though depending on the version, you might have to use .data("ui-autocomplete") instead.
And that's it, simple enough, but it works. Just make sure to check that your code matches the array of objects that you're pulling the items from.
Full example below:
$(".autocomplete").autocomplete({
minLength: 0,
source: response.cities,
focus: function (event, ui) {
$(".autocomplete").val(ui.item.Label);
return false;
},
select: function (event, ui) {
$(".autocomplete").val(ui.item.Label);
return false;
}
}).data("uiAutocomplete")._renderItem = function (ul, item) {
return $("<li>")
.append("<a>" + item.Label + "</a>")
.appendTo(ul);
};
Published at 9 Nov 2016, 07:08 AM
Tags: jQuery,JavaScript