I try to use jQuery UI Autocomplete function to show some data and select it. But I see some error in the console I get a javascript error (item is undefined). My code is
jq version: jquery-ui-1.10.3.custom.min.js jq-ui version: jquery-1.10.2.min.js
$("#searchterms").autocomplete({
minLength: 2,
source: '@(Url.RouteUrl("OrderSkuSearch"))',
focus: function (event, ui) {
$("#searchterms").val(ui.item.label);
$("#productid").val(ui.item.id);
console.log("focus: " + ui.item.id);
return false;
},
select: function (event, ui) {
$("#searchterms").val(ui.item.value);
$("#productid").val(ui.item.id);
console.log("select: " + ui.item.id);
return false;
},
autoFocus: true,
delay: 3000
})
.data("ui-autocomplete")._renderItem = function (ul, item) {
//if ($("#productid").val() == "") {
// $("#productid").val(item.id);
//}
$("#productid").val(item.id);
return $("<li>")
.append("<a>" + item.value + ">" + item.label + "</a>")
.appendTo(ul);
};
The return type is list:
[{"label":"Build your own computer","value":"COMP_CUST","id":1}]
.append("<a>" + item.value + ">" + item.label + "</a>")
and this does not make proper HTML Syntax. Would suggest you provide an example of the data returned by your URL when query is sent. – Twisty May 10 '19 at 5:35