If you see this Fiddle demo, not done by me, how can I then avoid that the keyboard can go down and choose the disabled element? The mouse is working fine (not being able to select it) but I can go down with the keyboard and select it, resulting in an empty search :-/
The Fiddle demo is from this post, How to disable element in jQuery autocomplete list
jQuery code:
$(function () {
var availableTags = [
"ActionScript",
"AppleScript",
"Asp",
"BASIC",
"C",
"C++",
"Clojure",
"COBOL",
"ColdFusion",
"Erlang",
"Fortran",
"Groovy",
"Haskell",
"Java",
"JavaScript",
"Lisp",
"Perl",
"PHP",
"Python",
"Ruby",
"Scala",
"Scheme"];
$("#tags").autocomplete({
source: availableTags,
response: function (event, ui) {
if (ui.content.length > 3) {
while (ui.content.length > 3) {
ui.content.pop();
}
ui.content.push({
'label': 'Please narrow down your search',
'value': ''
});
}
}
}).data("ui-autocomplete")._renderItem = function (ul, item) {
return $("<li " + (item.value == '' ? 'class="ui-state-disabled"' : '') + ">")
.append("<a>" + item.label + "</a>")
.appendTo(ul);
};
});