Refactor ComboBoxWidget and settings form: remove unused handleComboAdd function, enhance form state serialization, and improve room option handling
This commit is contained in:
parent
31913eab47
commit
76d2799e05
3 changed files with 80 additions and 106 deletions
|
@ -74,27 +74,6 @@ const ComboBoxWidget = (() => {
|
|||
sorted.forEach(option => selectElement.appendChild(option));
|
||||
}
|
||||
|
||||
function handleComboAdd(inputId, listId, stateArray, label = 'entry') {
|
||||
const input = document.getElementById(inputId);
|
||||
const value = input.value.trim();
|
||||
if (!value) {
|
||||
alert(`Please enter a ${label}.`);
|
||||
return;
|
||||
}
|
||||
|
||||
const select = document.getElementById(listId);
|
||||
const exists = Array.from(select.options).some(opt => opt.textContent === value);
|
||||
if (exists) {
|
||||
alert(`${label.charAt(0).toUpperCase() + label.slice(1)} "${value}" already exists.`);
|
||||
return;
|
||||
}
|
||||
|
||||
const option = createOption(value); // Already built to handle temp IDs
|
||||
select.add(option);
|
||||
formState[stateArray].push(value);
|
||||
input.value = '';
|
||||
}
|
||||
|
||||
function initComboBox(ns, config = {}) {
|
||||
const input = document.querySelector(`#${ns}-input`);
|
||||
const list = document.querySelector(`#${ns}-list`);
|
||||
|
@ -168,9 +147,6 @@ const ComboBoxWidget = (() => {
|
|||
list.appendChild(option);
|
||||
|
||||
const key = config.stateArray ?? `${ns}s`; // fallback to pluralization
|
||||
if (Array.isArray(formState?.[key])) {
|
||||
formState[key].push({ name: newItem });
|
||||
}
|
||||
|
||||
if (config.sort !== false) {
|
||||
sortOptions(list);
|
||||
|
@ -203,7 +179,6 @@ const ComboBoxWidget = (() => {
|
|||
initComboBox,
|
||||
createOption,
|
||||
sortOptions,
|
||||
handleComboAdd,
|
||||
createTempId
|
||||
};
|
||||
})();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue