Latest updates.
This commit is contained in:
parent
d1f00cd9d5
commit
7d4b76d19f
3 changed files with 41 additions and 6 deletions
|
|
@ -32,7 +32,7 @@ def init_search_routes(app):
|
|||
{"field": "location.label", "label": "Location"},
|
||||
]
|
||||
inventory_results = inventory_service.list({
|
||||
'notes|label|model|owner.label__icontains': q,
|
||||
'notes|label|model|serial|barcode|name|owner.label__icontains': q,
|
||||
'fields': [
|
||||
"label",
|
||||
"name",
|
||||
|
|
|
|||
|
|
@ -64,7 +64,44 @@ DropDown.utilities = {
|
|||
}
|
||||
|
||||
function onShow(e) {
|
||||
setMenuMaxHeight(e.target);
|
||||
// Bootstrap delegated events: currentTarget is document, useless here.
|
||||
const source = e.target;
|
||||
|
||||
// Sanity check: make sure this is an Element before using .closest
|
||||
if (!(source instanceof Element)) {
|
||||
console.warn('Event target is not an Element:', source);
|
||||
return;
|
||||
}
|
||||
|
||||
// Whatever you were doing before
|
||||
setMenuMaxHeight(source);
|
||||
|
||||
// Walk up to the element with data-field
|
||||
const fieldElement = source.closest('[data-field]');
|
||||
if (!fieldElement) {
|
||||
console.warn('No [data-field] ancestor found for', source);
|
||||
return;
|
||||
}
|
||||
|
||||
const fieldName = fieldElement.dataset.field;
|
||||
if (!fieldName) {
|
||||
console.warn('Element has no data-field value:', fieldElement);
|
||||
return;
|
||||
}
|
||||
|
||||
const input = document.getElementById(`${fieldName}-filter`);
|
||||
if (!input) {
|
||||
console.warn(`No element found with id "${fieldName}-filter"`);
|
||||
return;
|
||||
}
|
||||
|
||||
// Let Bootstrap finish its show animation / DOM fiddling
|
||||
setTimeout(() => {
|
||||
input.focus();
|
||||
if (typeof input.select === 'function') {
|
||||
input.select();
|
||||
}
|
||||
}, 0);
|
||||
}
|
||||
|
||||
function onResize() {
|
||||
|
|
@ -78,7 +115,7 @@ DropDown.utilities = {
|
|||
|
||||
function init(root = document) {
|
||||
// Delegate so dynamically-added dropdowns work too
|
||||
root.addEventListener('show.bs.dropdown', onShow);
|
||||
root.addEventListener('shown.bs.dropdown', onShow);
|
||||
window.addEventListener('resize', onResize);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -35,10 +35,8 @@
|
|||
{% else %}
|
||||
{% set sel_label = "-- Select --" %}
|
||||
{% endif %}
|
||||
<!-- button type="button" class="btn btn-outline-dark d-block w-100 text-start dropdown-toggle inventory-dropdown"
|
||||
id="{{ field_name }}-button" data-bs-toggle="dropdown" data-value="{{ value }}">{{ sel_label }}</button -->
|
||||
<input type="button" class="form-control btn btn-outline-dark d-block w-100 text-start dropdown-toggle inventory-dropdown"
|
||||
id="{{ field_name }}-button" data-bs-toggle="dropdown" data-value="{{ value }}" value="{{ sel_label }}">
|
||||
id="{{ field_name }}-button" data-bs-toggle="dropdown" data-value="{{ value }}" data-field="{{ field_name }}" value="{{ sel_label }}">
|
||||
<div class="dropdown-menu pt-0" id="{{ field_name }}-dropdown">
|
||||
<input type="text" class="form-control mt-0 border-top-0 border-start-0 border-end-0 rounded-bottom-0"
|
||||
id="{{ field_name }}-filter" placeholder="Filter..." oninput="DropDown.utilities.filterList('{{ field_name }}')">
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue