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

6
package-lock.json generated
View File

@@ -4877,7 +4877,11 @@
}, },
"packages/declaform": { "packages/declaform": {
"version": "1.0.0", "version": "1.0.0",
"license": "ISC" "license": "ISC",
"dependencies": {
"ajv": "^8.17.1",
"ajv-formats": "^3.0.1"
}
}, },
"packages/json-schema": { "packages/json-schema": {
"version": "1.0.0", "version": "1.0.0",

View File

@@ -71,9 +71,9 @@ class Field {
(this._inputs as HTMLInputElement[]) (this._inputs as HTMLInputElement[])
.forEach(input => { .forEach(input => {
if (input.value === val) { if (input.value === val) {
input.setAttribute('checked', ''); input.checked = true;
} else { } else {
input.removeAttribute('checked'); input.checked = false;
} }
}); });
break; break;

View File

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

View File

@@ -6,6 +6,7 @@
"module": "esnext", "module": "esnext",
"target": "es6", "target": "es6",
"types": [], "types": [],
"lib": ["es2017", "dom"],
// Other Outputs // Other Outputs
"sourceMap": true, "sourceMap": true,