Skip to content

Commit

Permalink
Make sure that only one radio button is checked in its group (bug 186…
Browse files Browse the repository at this point in the history
…4136)

When the first checked radio is met, the others in the group are set to false.
  • Loading branch information
calixteman committed Nov 23, 2023
1 parent 5781e72 commit 1f0f516
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 5 deletions.
15 changes: 15 additions & 0 deletions src/display/annotation_layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -1637,6 +1637,21 @@ class RadioButtonWidgetAnnotationElement extends WidgetAnnotationElement {
storage.setValue(id, { value });
}

if (value) {
// It's possible that multiple radio buttons are checked.
// So if this one is checked we just reset the other ones.
// (see bug 1864136). Then when the other ones will be rendered they will
// unchecked (because of their value in the storage).
// Consequently, the first checked radio button will be the only checked
// one.
for (const radio of this._getElementsByName(
data.fieldName,
/* skipId = */ id
)) {
storage.setValue(radio.id, { value: false });
}
}

const element = document.createElement("input");
GetElementsByNameSet.add(element);
element.setAttribute("data-element-id", id);
Expand Down
14 changes: 11 additions & 3 deletions test/driver.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,8 @@ class Rasterize {
outputScale,
annotations,
annotationCanvasMap,
annotationStorage,
fieldObjects,
page,
imageResourcesPath,
renderForms = false
Expand All @@ -244,6 +246,8 @@ class Rasterize {
linkService: new SimpleLinkService(),
imageResourcesPath,
renderForms,
annotationStorage,
fieldObjects,
};

// Ensure that the annotationLayer gets translated.
Expand Down Expand Up @@ -682,6 +686,10 @@ class Driver {
}
}

if (task.forms) {
task.fieldObjects = await doc.getFieldObjects();
}

this._nextPage(task, failure);
},
err => {
Expand Down Expand Up @@ -928,9 +936,7 @@ class Driver {
transform,
};
if (renderForms) {
renderContext.annotationMode = task.annotationStorage
? AnnotationMode.ENABLE_STORAGE
: AnnotationMode.ENABLE_FORMS;
renderContext.annotationMode = AnnotationMode.ENABLE_FORMS;
} else if (renderPrint) {
if (task.annotationStorage) {
renderContext.annotationMode = AnnotationMode.ENABLE_STORAGE;
Expand Down Expand Up @@ -984,6 +990,8 @@ class Driver {
outputScale,
data,
annotationCanvasMap,
task.pdfDoc.annotationStorage,
task.fieldObjects,
page,
IMAGE_RESOURCES_PATH,
renderForms
Expand Down
16 changes: 14 additions & 2 deletions test/integration/scripting_spec.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2261,9 +2261,15 @@ describe("Interaction", () => {
expect(storage)
.withContext(`In ${browserName}`)
.toEqual({
"22R": { value: false },
"25R": { value: true },
"28R": { value: false },
"35R": { value: false },
"38R": { value: false },
"41R": { value: false },
"44R": { value: false },
"47R": { value: false },
"50R": { value: false },
"22R": { value: false },
});

await page.click(getSelector("22R"));
Expand All @@ -2273,9 +2279,15 @@ describe("Interaction", () => {
expect(storage)
.withContext(`In ${browserName}`)
.toEqual({
"22R": { value: true },
"25R": { value: false },
"28R": { value: false },
"35R": { value: false },
"38R": { value: false },
"41R": { value: false },
"44R": { value: false },
"47R": { value: false },
"50R": { value: false },
"22R": { value: true },
});
})
);
Expand Down
2 changes: 2 additions & 0 deletions test/pdfs/bug1864136.pdf.link
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
https://bugzilla.mozilla.org/attachment.cgi?id=9363183

11 changes: 11 additions & 0 deletions test/test_manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -8361,5 +8361,16 @@
"rotation": 0
}
}
},
{
"id": "bug1864136-forms",
"file": "pdfs/bug1864136.pdf",
"md5": "97357ad5b0fde2c4e79c07819e4d9710",
"rounds": 1,
"link": true,
"firstPage": 2,
"lastPage": 2,
"type": "eq",
"forms": true
}
]

0 comments on commit 1f0f516

Please sign in to comment.