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 Helenpaups on MVC forms in Umbraco
23 May 2018, 16:48 PM
By Helenpaups on MVC forms in Umbraco
23 May 2018, 13:46 PM
By AkikoTax on MVC forms in Umbraco
20 May 2018, 06:41 AM
By Klaus on MVC forms in Umbraco
17 May 2018, 10:47 AM
By Archie on MVC forms in Umbraco
16 May 2018, 18:52 PM
By w on JQuery Unobtrusive Validation for dynamically created elements
11 May 2018, 02:00 AM
By Luke on Umbraco using Global.asax to handle events before the Request Handler.
27 Apr 2018, 18:28 PM
By Janine Gardiola on Umbraco using Global.asax to handle events before the Request Handler.
26 Apr 2018, 11:18 AM
Categories
App Development
Event
Game Development
Mapping
Modelling
Programming
Review
Robotics
Tutorial
Web Development