Navoneel Navoneel - 5 months ago 24
jQuery Question

Autocomplete show entire list on down arrow key

I have applied autocomplete plugin on a textbox like this.

var model = [];
for (var i = 0; i < data.length; ++i) {
model.push({ Label: data[i].ModelName, Value: data[i].CodeModel });
}
var modelData = model;
$('#tbmodele').autocomplete({
source: function (request, response) {
response($.map(modelData, function (value) {
if (value.Label.toLowerCase().startsWith(request.term.toLowerCase())) {
return {
label: value.Label,
vvalue: value.Value
};
}
}));
},
select: function (e, i) {
populateOtherFields(i.item.label);
return false;
},
open: function () {
$scope.isModelDropdownOpen = true;
},
minLength: 0,
scroll: true
});


Now I want to open the autocomplete list on pressing down arrow key of that text field.

Can anyone please suggest how I can do that?

Answer

Bind the down arrow key to autocomplete's search method:

$(document).on('keydown', '#tbmodele', function() {
   $('#tbmodele').autocomplete('search', '');
});