Hi. I'm a newbie programmer / designer trying to configure jquery ui autocomplete. I have it working, using a javascript object (array). The array contains retailer stores that we are directing our customers to. We have certain stores that are preferred and so we would like for them to come up earlier than other stores but I don't really know how to filter them into the result or if it is even possible.
I want "Widget Store 4" to appear first if anyone types in "Widget". Here's the jquery code:
var widgetstores = [
{label: "Widget Store 1", value: "1001" }, {label: "Widget Store 2", value: "1002" }, {label: "Widget Store 3", value: "1003" }, {label: "Widget Store 4", value: "1004" }, {label: "Widget Store 5", value: "1005" }, {label: "Widget Store 6", value: "1006" }
]
$(function() {
$('#tags').autocomplete({
minLength: 3,
source: widgetstores,
focus: function(event, ui) {
$('#tags').val(ui.item.label);
return false;
},
select: function(event, ui) {
$('#tags').val(ui.item.label);
$('#customer_num').val(ui.item.value);
return false;
}
})
.data( "autocomplete" )._renderItem = function( ul, item ) {
return $( "<li></li>" )
.data( "item.autocomplete", item )
.append( "<a>" + item.label + "</a>" )
.appendTo( ul );
};
});