Fix how radio 'checked' properties are set.

This commit is contained in:
Austin Smith
2025-11-19 08:39:27 -05:00
parent 4d1a652e84
commit a3b9ee2f99
4 changed files with 12 additions and 7 deletions

View File

@@ -179,7 +179,7 @@ function getInputValue(id: string) {
}
function setRadioValue(name: string, value: string) {
const radios = document.querySelectorAll(`[name="${name}"]`);
const radios = document.querySelectorAll(`[name="${name}"]`) as NodeListOf<HTMLInputElement>;
if (!radios) {
throw new Error(`No radios with name "${name}"!`);
}
@@ -187,11 +187,11 @@ function setRadioValue(name: string, value: string) {
if (!('value' in radio)) {
throw new Error('Radio option does not have "value" attribute!');
}
radio.removeAttribute('checked');
radio.checked = false;
})
const option = ([...radios] as HTMLInputElement[]).find(x => x.value);
const option = Array.from(radios).find(x => x.value);
if (!option) {
throw new Error(`No option with value "${value}"`);
}
option.setAttribute('checked', '');
option.checked = true;
}