I pretty new to JqueryUI and JQuery but managed to figure out how to get the autocomplete function with catergories.
Now i want to build my solution further, and i don't know if it is possible.
Basiclly i want the "dropdown"-ITEM(one item in the box, not category) on the textbox to have two different styles.
i want this:
<li class="ui-menu-item" role="presentation">
<a id="ui-id-28" class="ui-corner-all" tabindex="-1">I want it all</a>
<a class="mycssclass"> by Queen</a>
</li>
notice the extra anchor(last in the
Should i do some operation (append) on the widget-catcomplete function?
This is my Jquery:
$.widget("custom.catcomplete", $.ui.autocomplete, {
_renderMenu: function (ul, items) {
var that = this,
currentCategory = "";
$.each(items, function (index, item) {
if (item.category != currentCategory) {
ul.append("<li class='ui-autocomplete-category'>" + item.category + "</li>");
currentCategory = item.category;
}
that._renderItemData(ul, item);
});
}
});
$(function () {
$("#ListenToInput").catcomplete({
delay:0,
source: function (request, response) {
$.get("http://ws.spotify.com/search/1/track.json", { // Call Spotify WebService (JSON)
//currently selected in input
q: request.term //query for search
}, function (data) {
response($.map(data.tracks.slice(0, 5), function (item) {
return { label: item.name, by: item.artists[0].name, category: "Track" };
// returns five items of [{label: "Name"}{by: "Artist"}{category: "Track"}]
}));
});
}
});
});
I suspect i should do something with this line??:
that._renderItemData(ul, item);
UPDATE: I did a override on the _renderItem method, but somehow this messes up the "menuclick" event. The Value of item is undefined, dont know the solution to that nut.
$.ui.autocomplete.prototype._renderItem = function (ul, item) {
item.value = item.label +" - " + item.by;
return $("<li>")
.append($("<a>").text(item.label)
.append($("<a class='customclass'>").text(item.by)))
.appendTo(ul);
};
Thanks in regards.