diff --git a/routes.py b/routes.py index 4cb7cd9..886aa98 100644 --- a/routes.py +++ b/routes.py @@ -411,6 +411,22 @@ def settings(): flash("Invalid form state submitted. JSON decode failed.", "danger") traceback.print_exc() return redirect(url_for('main.settings')) + + # === 0. Create new Brands === + for name in state.get('brands', []): + clean = name.strip() + if clean: + print(f"🧪 Creating new brand: {clean}") + new_brand = Brand(name=clean) # type: ignore + db.session.add(new_brand) + + # === 0.5 Create new Types === + for name in state.get('types', []): + clean = name.strip() + if clean: + print(f"🧪 Creating new item type: {clean}") + new_type = Item(description=clean) # type: ignore + db.session.add(new_type) # === 1. Create new Sections === section_map = {} diff --git a/static/js/widget.js b/static/js/widget.js index fb6067a..323edbc 100644 --- a/static/js/widget.js +++ b/static/js/widget.js @@ -94,26 +94,22 @@ const ComboBoxWidget = (() => { } currentlyEditing = null; } else { - if (config.onAdd) { - config.onAdd(newItem, list, createOption); - } else { - // Default fallback here - if (config.stateArray && formState && formState[config.stateArray]) { - const exists = Array.from(list.options).some(opt => opt.textContent === newItem); - if (exists) { - alert(`"${newItem}" already exists.`); - return; - } - const option = createOption(newItem); - list.appendChild(option); - formState[config.stateArray].push(newItem); - if (config.sort !== false) { - sortOptions(list); - } - } else { - const option = createOption(newItem); - list.appendChild(option); - } + const exists = Array.from(list.options).some(opt => opt.textContent === newItem); + if (exists) { + alert(`"${newItem}" already exists.`); + return; + } + + const option = createOption(newItem); + list.appendChild(option); + + const key = config.stateArray ?? `${ns}s`; // fallback to pluralization + if (Array.isArray(formState?.[key])) { + formState[key].push(newItem); + } + + if (config.sort !== false) { + sortOptions(list); } } @@ -123,7 +119,6 @@ const ComboBoxWidget = (() => { updateAddButtonIcon(); }); - removeBtn.addEventListener('click', () => { Array.from(list.selectedOptions).forEach(option => { if (config.onRemove) { diff --git a/templates/fragments/_combobox_fragment.html b/templates/fragments/_combobox_fragment.html index fef929e..98d5ba8 100644 --- a/templates/fragments/_combobox_fragment.html +++ b/templates/fragments/_combobox_fragment.html @@ -21,19 +21,13 @@ - + {% endmacro %}