Skip to content

Commit 428702e

Browse files
committed
JS - reset correctly radio buttons
1 parent 4b49db7 commit 428702e

File tree

3 files changed

+18
-10
lines changed

3 files changed

+18
-10
lines changed

src/display/annotation_layer.js

+6-10
Original file line numberDiff line numberDiff line change
@@ -915,7 +915,7 @@ class CheckboxWidgetAnnotationElement extends WidgetAnnotationElement {
915915
element.type = "checkbox";
916916
element.name = this.data.fieldName;
917917
if (value) {
918-
element.setAttribute("checked", true);
918+
element.checked = true;
919919
}
920920
element.setAttribute("id", id);
921921

@@ -1000,9 +1000,8 @@ class RadioButtonWidgetAnnotationElement extends WidgetAnnotationElement {
10001000
element.type = "radio";
10011001
element.name = data.fieldName;
10021002
if (value) {
1003-
element.setAttribute("checked", true);
1003+
element.checked = true;
10041004
}
1005-
element.setAttribute("pdfButtonValue", data.buttonValue);
10061005
element.setAttribute("id", id);
10071006

10081007
element.addEventListener("change", function (event) {
@@ -1016,19 +1015,16 @@ class RadioButtonWidgetAnnotationElement extends WidgetAnnotationElement {
10161015
});
10171016

10181017
if (this.enableScripting && this.hasJSActions) {
1018+
const pdfButtonValue = data.buttonValue;
10191019
element.addEventListener("updatefromsandbox", event => {
10201020
const { detail } = event;
10211021
const actions = {
10221022
value() {
1023-
const fieldValue = detail.value;
1023+
const checked = pdfButtonValue === detail.value;
10241024
for (const radio of document.getElementsByName(event.target.name)) {
10251025
const radioId = radio.getAttribute("id");
1026-
if (fieldValue === radio.getAttribute("pdfButtonValue")) {
1027-
radio.setAttribute("checked", true);
1028-
storage.setValue(radioId, { value: true });
1029-
} else {
1030-
storage.setValue(radioId, { value: false });
1031-
}
1026+
radio.checked = radioId === id && checked;
1027+
storage.setValue(radioId, { value: radio.checked });
10321028
}
10331029
},
10341030
focus() {

src/scripting_api/field.js

+3
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,9 @@ class RadioButtonField extends Field {
481481
}
482482

483483
set value(value) {
484+
if (value === null) {
485+
this._value = "";
486+
}
484487
const i = this.exportValues.indexOf(value);
485488
if (0 <= i && i < this._radioIds.length) {
486489
this._id = this._radioIds[i];

test/integration/scripting_spec.js

+9
Original file line numberDiff line numberDiff line change
@@ -174,9 +174,15 @@ describe("Interaction", () => {
174174
it("must reset all", async () => {
175175
await Promise.all(
176176
pages.map(async ([browserName, page]) => {
177+
// click on a radio button
178+
await page.click("[data-annotation-id='449R']");
179+
177180
// this field has no actions but it must be cleared on reset
178181
await page.type("#\\34 05R", "employee", { delay: 200 });
179182

183+
let checked = await page.$eval("#\\34 49R", el => el.checked);
184+
expect(checked).toEqual(true);
185+
180186
// click on reset button
181187
await page.click("[data-annotation-id='402R']");
182188

@@ -194,6 +200,9 @@ describe("Interaction", () => {
194200

195201
const sum = await page.$eval("#\\34 27R", el => el.value);
196202
expect(sum).toEqual("");
203+
204+
checked = await page.$eval("#\\34 49R", el => el.checked);
205+
expect(checked).toEqual(false);
197206
})
198207
);
199208
});

0 commit comments

Comments
 (0)