Refactor code structure; improve organization and readability across multiple files
This commit is contained in:
parent
774c28e761
commit
acacf39f8e
14 changed files with 380 additions and 217 deletions
|
@ -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) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue