From a3b9ee2f9941fe66f345268013045d3068321bb4 Mon Sep 17 00:00:00 2001 From: Austin Smith Date: Wed, 19 Nov 2025 08:39:27 -0500 Subject: [PATCH] Fix how radio 'checked' properties are set. --- package-lock.json | 6 +++++- packages/declaform/src/index.ts | 4 ++-- packages/declaform/tests/declaform.test.ts | 8 ++++---- tsconfig.json | 1 + 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/package-lock.json b/package-lock.json index 14264e6..7c62957 100644 --- a/package-lock.json +++ b/package-lock.json @@ -4877,7 +4877,11 @@ }, "packages/declaform": { "version": "1.0.0", - "license": "ISC" + "license": "ISC", + "dependencies": { + "ajv": "^8.17.1", + "ajv-formats": "^3.0.1" + } }, "packages/json-schema": { "version": "1.0.0", diff --git a/packages/declaform/src/index.ts b/packages/declaform/src/index.ts index aea96ef..6720b27 100644 --- a/packages/declaform/src/index.ts +++ b/packages/declaform/src/index.ts @@ -71,9 +71,9 @@ class Field { (this._inputs as HTMLInputElement[]) .forEach(input => { if (input.value === val) { - input.setAttribute('checked', ''); + input.checked = true; } else { - input.removeAttribute('checked'); + input.checked = false; } }); break; diff --git a/packages/declaform/tests/declaform.test.ts b/packages/declaform/tests/declaform.test.ts index 9a3302f..19b4f14 100644 --- a/packages/declaform/tests/declaform.test.ts +++ b/packages/declaform/tests/declaform.test.ts @@ -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; 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; } \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.json index e33540c..055cd7d 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -6,6 +6,7 @@ "module": "esnext", "target": "es6", "types": [], + "lib": ["es2017", "dom"], // Other Outputs "sourceMap": true,