Skip to content

Commit

Permalink
fix disabled enum value getting selected as default
Browse files Browse the repository at this point in the history
add failsafe for fully-disabled enums
  • Loading branch information
Govorunb committed Jul 7, 2024
1 parent f343818 commit 535b9a6
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions frontend/www/src/modules/modal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -339,16 +339,23 @@ async function addDropdown(modal: HTMLElement, param: EnumParam) {
setupField(field, select, param);
for (let i = 0; i < options.length; i++) {
const option = document.createElement("option");
const name = options[i];
option.value = i.toString();
option.disabled = options[i].startsWith('[DISABLED] ');
option.textContent = options[i].replace(/\[DISABLED\] /g, '');
option.disabled = name.startsWith('[DISABLED] ');
option.textContent = name.substring(option.disabled ? 11 : 0);
select.appendChild(option);
}
const firstEnabled = Array.from(select.options).findIndex(op => !op.disabled);
if (firstEnabled < 0 || firstEnabled >= select.options.length) {
console.error(`No enabled options in enum ${param.type}`);
showErrorModal("Config error", `This redeem is misconfigured, please message AlexejheroDev\nError: ${param.type} has no enabled options`);
return;
}

if (param.defaultValue !== undefined) {
select.value = param.defaultValue;
} else {
select.value = select.options[0].value;
select.value = select.options[firstEnabled].value;
}
modal.appendChild(field);
}
Expand Down

0 comments on commit 535b9a6

Please sign in to comment.