/**
* Utilities for populating settings form controls and synchronizing option values.
*/
/**
* Populates a select dropdown with options from a models map.
* @param {HTMLSelectElement|null} selectEl - Target select element.
* @param {object} models - Key-value map of model definitions.
* @param {string|null} [selectedKey=null] - Key of the option to mark selected.
*/
export function populateModelDropdown(selectEl, models, selectedKey = null) {
if (!selectEl) return;
selectEl.innerHTML = '';
if (!models || typeof models !== 'object') return;
for (const key in models) {
if (Object.prototype.hasOwnProperty.call(models, key)) {
const model = models[key];
const option = document.createElement('option');
option.value = key;
option.textContent = `${model.name || key} (${model.description || ''})`;
if (selectedKey && key === selectedKey) {
option.selected = true;
}
selectEl.appendChild(option);
}
}
}
settings-utils.js
×
Type: Web, text/plain
949 Bytes
Last Modified 2026-09-04 14:23:27
⬇ Download File
Type: Web, text/plain
949 Bytes
Last Modified 2026-09-04 14:23:27
⬇ Download File