diff --git a/static/js/autocomplete_model.js b/static/js/autocomplete_model.js index aa1d220cceb72b4c12e5e3a6042212194c1a89c6..6e135ad133aac43309d30ddcca0ffda46d49de18 100644 --- a/static/js/autocomplete_model.js +++ b/static/js/autocomplete_model.js @@ -18,7 +18,8 @@ $(document).ready(function () { html += li(prefix + "_" + obj.id, obj[name_field]); }); - $("#" + prefix + "_list").html(html); + let results_list = $("#" + prefix + "_list"); + results_list.html(html); objects.results.forEach(function (obj) { $("#" + prefix + "_" + obj.id).click(function() { @@ -32,6 +33,10 @@ $(document).ready(function () { if (input === obj[name_field]) $("#" + prefix + "_pk").val(obj.id); }); + + if (results_list.children().length === 1 && e.originalEvent.keyCode >= 32) { + results_list.children().first().trigger("click"); + } }); }); }); \ No newline at end of file diff --git a/static/js/base.js b/static/js/base.js index fdad58d7d40e1696cd4856450f4b12fd16633e74..f485635bb5393ca5919c9f6abdda94906f12a9a7 100644 --- a/static/js/base.js +++ b/static/js/base.js @@ -86,8 +86,8 @@ function getMatchedNotes(pattern, fun) { * Generate a <li> entry with a given id and text */ function li(id, text, extra_css) { - return "<li class=\"list-group-item py-1 px-2 d-flex justify-content-between align-items-center text-truncate " + extra_css + "\"" + - " id=\"" + id + "\">" + text + "</li>\n"; + return "<li class=\"list-group-item py-1 px-2 d-flex justify-content-between align-items-center text-truncate " + + (extra_css ? extra_css : "") + "\"" + " id=\"" + id + "\">" + text + "</li>\n"; } /**