Refactor code structure; improve organization and readability across multiple files

This commit is contained in:
Yaro Kasear 2025-06-23 14:51:21 -05:00
parent 774c28e761
commit acacf39f8e
14 changed files with 380 additions and 217 deletions

View file

@ -30,7 +30,7 @@ const ComboBoxWidget = (() => {
return;
}
const option = new Option(value, value);
const option = createOption(value); // Already built to handle temp IDs
select.add(option);
formState[stateArray].push(value);
input.value = '';
@ -94,6 +94,11 @@ const ComboBoxWidget = (() => {
}
currentlyEditing = null;
} else {
if (config.onAdd) {
config.onAdd(newItem, list, createOption);
return; // Skip the default logic!
}
const exists = Array.from(list.options).some(opt => opt.textContent === newItem);
if (exists) {
alert(`"${newItem}" already exists.`);
@ -105,7 +110,7 @@ const ComboBoxWidget = (() => {
const key = config.stateArray ?? `${ns}s`; // fallback to pluralization
if (Array.isArray(formState?.[key])) {
formState[key].push(newItem);
formState[key].push({ name: newItem });
}
if (config.sort !== false) {