Refactor settings logic; streamline brand and item type creation, enhance ComboBoxWidget integration for improved usability

This commit is contained in:
Yaro Kasear 2025-06-23 10:13:22 -05:00
parent c6fc1a4795
commit 347baaa12e
3 changed files with 40 additions and 35 deletions

View file

@ -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) {