I'm having quite a bit of trouble getting select or the focus functions to respond. I can't even kill the results in the select once I expand the results. I read a lot about certain versions of jQuery UI conflicting with the main jQuery library but pretty much any combination doesn't seem to work. Worse, it's not throwing any errors in console. Everything below select/focus seem to work fine. I am appending some HTML to each item and in my application I am styling them different based on a class. I would like to use select to append some extra HTML using ui.item.label below the input itself (like a tagging system). I am just using the alert to troubleshoot in the meantime.
Here is a fiddle that has my half-working code.
$(function () {
var availableItems = [{
value: "recent",
label: "Recent",
classN: "heading"
}, {
value: "all",
label: "All",
classN: "all"
}, {
value: "lorem",
label: "Lorem",
classN: "lorem"
}, ];
$(".post-to").autocomplete({
source: availableItems,
minLength: 0,
focus: function (event, ui) {
$('.post-to').val(ui.item.label);
alert(ui.item.label);
return false;
},
select: function (event, ui) {
alert(ui.item.label);
return false;
}
}).on("focus", function () {
$(this).autocomplete("search", '');
}).data("ui-autocomplete")._renderItem = function (ul, item) {
return $("<li></li>")
.data("item.autocomplete", item)
.append("<span class='" + item.classN + "'></span><span>" + item.label + "</span>")
.appendTo(ul);
};
});