mirror of https://gitlab.crans.org/bde/nk20
Better autocomplete field
This commit is contained in:
parent
2f018f8c9d
commit
f148c8dacb
|
@ -18,7 +18,8 @@ $(document).ready(function () {
|
||||||
html += li(prefix + "_" + obj.id, obj[name_field]);
|
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) {
|
objects.results.forEach(function (obj) {
|
||||||
$("#" + prefix + "_" + obj.id).click(function() {
|
$("#" + prefix + "_" + obj.id).click(function() {
|
||||||
|
@ -32,6 +33,10 @@ $(document).ready(function () {
|
||||||
if (input === obj[name_field])
|
if (input === obj[name_field])
|
||||||
$("#" + prefix + "_pk").val(obj.id);
|
$("#" + prefix + "_pk").val(obj.id);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (results_list.children().length === 1 && e.originalEvent.keyCode >= 32) {
|
||||||
|
results_list.children().first().trigger("click");
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
|
@ -86,8 +86,8 @@ function getMatchedNotes(pattern, fun) {
|
||||||
* Generate a <li> entry with a given id and text
|
* Generate a <li> entry with a given id and text
|
||||||
*/
|
*/
|
||||||
function li(id, text, extra_css) {
|
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 + "\"" +
|
return "<li class=\"list-group-item py-1 px-2 d-flex justify-content-between align-items-center text-truncate "
|
||||||
" id=\"" + id + "\">" + text + "</li>\n";
|
+ (extra_css ? extra_css : "") + "\"" + " id=\"" + id + "\">" + text + "</li>\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue