Merge pull request #17318 from calixteman/bug1864136_2

Make sure that only one radio button is checked in its group (bug 1864136)
This commit is contained in:
calixteman 2023-11-24 08:40:23 +01:00 committed by GitHub
commit d679078beb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 53 additions and 5 deletions

View File

@ -1637,6 +1637,21 @@ class RadioButtonWidgetAnnotationElement extends WidgetAnnotationElement {
storage.setValue(id, { value }); 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"); const element = document.createElement("input");
GetElementsByNameSet.add(element); GetElementsByNameSet.add(element);
element.setAttribute("data-element-id", id); element.setAttribute("data-element-id", id);

View File

@ -219,6 +219,8 @@ class Rasterize {
outputScale, outputScale,
annotations, annotations,
annotationCanvasMap, annotationCanvasMap,
annotationStorage,
fieldObjects,
page, page,
imageResourcesPath, imageResourcesPath,
renderForms = false renderForms = false
@ -244,6 +246,8 @@ class Rasterize {
linkService: new SimpleLinkService(), linkService: new SimpleLinkService(),
imageResourcesPath, imageResourcesPath,
renderForms, renderForms,
annotationStorage,
fieldObjects,
}; };
// Ensure that the annotationLayer gets translated. // Ensure that the annotationLayer gets translated.
@ -682,6 +686,10 @@ class Driver {
} }
} }
if (task.forms) {
task.fieldObjects = await doc.getFieldObjects();
}
this._nextPage(task, failure); this._nextPage(task, failure);
}, },
err => { err => {
@ -928,9 +936,7 @@ class Driver {
transform, transform,
}; };
if (renderForms) { if (renderForms) {
renderContext.annotationMode = task.annotationStorage renderContext.annotationMode = AnnotationMode.ENABLE_FORMS;
? AnnotationMode.ENABLE_STORAGE
: AnnotationMode.ENABLE_FORMS;
} else if (renderPrint) { } else if (renderPrint) {
if (task.annotationStorage) { if (task.annotationStorage) {
renderContext.annotationMode = AnnotationMode.ENABLE_STORAGE; renderContext.annotationMode = AnnotationMode.ENABLE_STORAGE;
@ -984,6 +990,8 @@ class Driver {
outputScale, outputScale,
data, data,
annotationCanvasMap, annotationCanvasMap,
task.pdfDoc.annotationStorage,
task.fieldObjects,
page, page,
IMAGE_RESOURCES_PATH, IMAGE_RESOURCES_PATH,
renderForms renderForms

View File

@ -2261,9 +2261,15 @@ describe("Interaction", () => {
expect(storage) expect(storage)
.withContext(`In ${browserName}`) .withContext(`In ${browserName}`)
.toEqual({ .toEqual({
"22R": { value: false },
"25R": { value: true }, "25R": { value: true },
"28R": { 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: false },
}); });
await page.click(getSelector("22R")); await page.click(getSelector("22R"));
@ -2273,9 +2279,15 @@ describe("Interaction", () => {
expect(storage) expect(storage)
.withContext(`In ${browserName}`) .withContext(`In ${browserName}`)
.toEqual({ .toEqual({
"22R": { value: true },
"25R": { value: false }, "25R": { value: false },
"28R": { 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 },
}); });
}) })
); );

View File

@ -0,0 +1,2 @@
https://bugzilla.mozilla.org/attachment.cgi?id=9363183

View File

@ -8361,5 +8361,16 @@
"rotation": 0 "rotation": 0
} }
} }
},
{
"id": "bug1864136-forms",
"file": "pdfs/bug1864136.pdf",
"md5": "97357ad5b0fde2c4e79c07819e4d9710",
"rounds": 1,
"link": true,
"firstPage": 2,
"lastPage": 2,
"type": "eq",
"forms": true
} }
] ]