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

Tags: jQuery,JavaScript

Luke Alderton

Comments

Post a comment
Sit tight...
We're adding your comment.
Thank you.
Your comment has been added.
There's been a problem.
Please try again later.
Share with
Tags
Latest Comments
By Raymondpef on MVC forms in Umbraco
20 Nov 2018, 23:58 PM
By svetikNoupt on MVC forms in Umbraco
20 Nov 2018, 19:44 PM
By Lestersep on MVC forms in Umbraco
17 Nov 2018, 13:55 PM
By nseo-sw.men on MVC forms in Umbraco
17 Nov 2018, 00:43 AM
By shale.larosh on MVC forms in Umbraco
16 Nov 2018, 22:34 PM
By EdwardPhova on MVC forms in Umbraco
16 Nov 2018, 12:40 PM
By svetikNoupt on MVC forms in Umbraco
13 Nov 2018, 22:04 PM
By nseo-sw.men on MVC forms in Umbraco
13 Nov 2018, 17:47 PM
Categories
App Development
Event
Game Development
Mapping
Modelling
Programming
Review
Robotics
Tutorial
Web Development