diff --git a/inventory/routes/search.py b/inventory/routes/search.py index 7a605ae..8bc4950 100644 --- a/inventory/routes/search.py +++ b/inventory/routes/search.py @@ -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", diff --git a/inventory/static/js/components/dropdown.js b/inventory/static/js/components/dropdown.js index 72bc8e8..90ae355 100644 --- a/inventory/static/js/components/dropdown.js +++ b/inventory/static/js/components/dropdown.js @@ -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); } diff --git a/inventory/templates/crudkit/field.html b/inventory/templates/crudkit/field.html index aa33953..bf6f749 100644 --- a/inventory/templates/crudkit/field.html +++ b/inventory/templates/crudkit/field.html @@ -35,10 +35,8 @@ {% else %} {% set sel_label = "-- Select --" %} {% endif %} - + id="{{ field_name }}-button" data-bs-toggle="dropdown" data-value="{{ value }}" data-field="{{ field_name }}" value="{{ sel_label }}">