mirror of https://gitlab.crans.org/bde/nk20
Better user search to add friendships
This commit is contained in:
parent
442a5c5e36
commit
dc69faaf1d
|
@ -13,21 +13,29 @@ $(document).ready(function () {
|
||||||
$('#' + prefix + '_reset').removeClass('d-none')
|
$('#' + prefix + '_reset').removeClass('d-none')
|
||||||
|
|
||||||
$.getJSON(api_url + (api_url.includes('?') ? '&' : '?') + 'format=json&search=^' + input + api_url_suffix, function (objects) {
|
$.getJSON(api_url + (api_url.includes('?') ? '&' : '?') + 'format=json&search=^' + input + api_url_suffix, function (objects) {
|
||||||
let html = ''
|
let html = '<ul class="list-group list-group-flush" id="' + prefix + '_list">'
|
||||||
|
|
||||||
objects.results.forEach(function (obj) {
|
objects.results.forEach(function (obj) {
|
||||||
html += li(prefix + '_' + obj.id, obj[name_field])
|
html += li(prefix + '_' + obj.id, obj[name_field])
|
||||||
})
|
})
|
||||||
|
html += '</ul>'
|
||||||
|
|
||||||
const results_list = $('#' + prefix + '_list')
|
target.tooltip({
|
||||||
results_list.html(html)
|
html: true,
|
||||||
|
placement: 'bottom',
|
||||||
|
trigger: 'manual',
|
||||||
|
container: target.parent(),
|
||||||
|
fallbackPlacement: 'clockwise'
|
||||||
|
})
|
||||||
|
|
||||||
|
target.attr("data-original-title", html).tooltip("show")
|
||||||
|
|
||||||
objects.results.forEach(function (obj) {
|
objects.results.forEach(function (obj) {
|
||||||
$('#' + prefix + '_' + obj.id).click(function () {
|
$('#' + prefix + '_' + obj.id).click(function () {
|
||||||
target.val(obj[name_field])
|
target.val(obj[name_field])
|
||||||
$('#' + prefix + '_pk').val(obj.id)
|
$('#' + prefix + '_pk').val(obj.id)
|
||||||
|
|
||||||
results_list.html('')
|
target.tooltip("hide")
|
||||||
target.removeClass('is-invalid')
|
target.removeClass('is-invalid')
|
||||||
target.addClass('is-valid')
|
target.addClass('is-valid')
|
||||||
|
|
||||||
|
@ -37,8 +45,8 @@ $(document).ready(function () {
|
||||||
if (input === obj[name_field]) { $('#' + prefix + '_pk').val(obj.id) }
|
if (input === obj[name_field]) { $('#' + prefix + '_pk').val(obj.id) }
|
||||||
})
|
})
|
||||||
|
|
||||||
if (results_list.children().length === 1 && e.originalEvent.keyCode >= 32) {
|
if (objects.results.length === 1 && e.originalEvent.keyCode >= 32) {
|
||||||
results_list.children().first().trigger('click')
|
$('#' + prefix + '_' + objects.results[0].id).trigger('click')
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
@ -9,9 +9,9 @@ SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
name="{{ widget.name }}_name" autocomplete="off"
|
name="{{ widget.name }}_name" autocomplete="off"
|
||||||
{% for name, value in widget.attrs.items %}
|
{% for name, value in widget.attrs.items %}
|
||||||
{% ifnotequal value False %}{{ name }}{% ifnotequal value True %}="{{ value|stringformat:'s' }}"{% endifnotequal %}{% endifnotequal %}
|
{% ifnotequal value False %}{{ name }}{% ifnotequal value True %}="{{ value|stringformat:'s' }}"{% endifnotequal %}{% endifnotequal %}
|
||||||
{% endfor %}>
|
{% endfor %}
|
||||||
|
aria-describedby="{{widget.attrs.id}}_tooltip">
|
||||||
{% if widget.resetable %}
|
{% if widget.resetable %}
|
||||||
<a id="{{ widget.attrs.id }}_reset" class="btn btn-light autocomplete-reset{% if not widget.value %} d-none{% endif %}">{% trans "Reset" %}</a>
|
<a id="{{ widget.attrs.id }}_reset" class="btn btn-light autocomplete-reset{% if not widget.value %} d-none{% endif %}">{% trans "Reset" %}</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<ul class="list-group list-group-flush" id="{{ widget.attrs.id }}_list">
|
|
||||||
</ul>
|
|
||||||
|
|
Loading…
Reference in New Issue