diff --git a/src/core/annotation.js b/src/core/annotation.js index 8520cc3e5..a77767bac 100644 --- a/src/core/annotation.js +++ b/src/core/annotation.js @@ -3190,6 +3190,9 @@ class ButtonWidgetAnnotation extends WidgetAnnotation { this._streams.push(this.uncheckedAppearance); } this._fallbackFontDict = this.fallbackFontDict; + if (this.data.defaultFieldValue === null) { + this.data.defaultFieldValue = "Off"; + } } _processRadioButton(params) { @@ -3238,6 +3241,9 @@ class ButtonWidgetAnnotation extends WidgetAnnotation { this._streams.push(this.uncheckedAppearance); } this._fallbackFontDict = this.fallbackFontDict; + if (this.data.defaultFieldValue === null) { + this.data.defaultFieldValue = "Off"; + } } _processPushButton(params) { diff --git a/src/display/annotation_layer.js b/src/display/annotation_layer.js index 306b74c8d..ba9cfb997 100644 --- a/src/display/annotation_layer.js +++ b/src/display/annotation_layer.js @@ -373,11 +373,7 @@ class AnnotationElement { event.target.title = event.detail.userName; }, readonly: event => { - if (event.detail.readonly) { - event.target.setAttribute("readonly", ""); - } else { - event.target.removeAttribute("readonly"); - } + event.target.disabled = event.detail.readonly; }, required: event => { this._setRequired(event.target, event.detail.required); diff --git a/src/scripting_api/doc.js b/src/scripting_api/doc.js index 86da32249..bbc4c4d9f 100644 --- a/src/scripting_api/doc.js +++ b/src/scripting_api/doc.js @@ -1185,7 +1185,7 @@ class Doc extends PDFObject { resetForm(aFields = null) { // Handle the case resetForm({ aFields: ... }) - if (aFields && typeof aFields === "object") { + if (aFields && typeof aFields === "object" && !Array.isArray(aFields)) { aFields = aFields.aFields; } diff --git a/test/integration/scripting_spec.js b/test/integration/scripting_spec.js index d1e84fff5..cfaef62e2 100644 --- a/test/integration/scripting_spec.js +++ b/test/integration/scripting_spec.js @@ -2098,4 +2098,60 @@ describe("Interaction", () => { ); }); }); + + describe("in issue16863.pdf", () => { + let pages; + + beforeAll(async () => { + pages = await loadAndWait("issue16863.pdf", getSelector("334R")); + }); + + afterAll(async () => { + await closePages(pages); + }); + + it("must check that checkboxes are correctly resetted", async () => { + await Promise.all( + pages.map(async ([browserName, page]) => { + await page.waitForFunction( + "window.PDFViewerApplication.scriptingReady === true" + ); + + let readonly = await page.$eval( + getSelector("353R"), + el => el.disabled + ); + expect(readonly).withContext(`In ${browserName}`).toEqual(true); + await page.click(getSelector("334R")); + await page.waitForTimeout(10); + + readonly = await page.$eval(getSelector("353R"), el => el.disabled); + expect(readonly).withContext(`In ${browserName}`).toEqual(true); + await page.click(getSelector("351R")); + await page.waitForTimeout(10); + + readonly = await page.$eval(getSelector("353R"), el => el.disabled); + expect(readonly).withContext(`In ${browserName}`).toEqual(true); + await page.click(getSelector("352R")); + await page.waitForTimeout(10); + + readonly = await page.$eval(getSelector("353R"), el => el.disabled); + expect(readonly).withContext(`In ${browserName}`).toEqual(false); + + await page.click(getSelector("353R")); + await page.waitForTimeout(10); + + let checked = await page.$eval(getSelector("353R"), el => el.checked); + expect(checked).withContext(`In ${browserName}`).toEqual(true); + await page.click(getSelector("334R")); + await page.waitForTimeout(10); + + readonly = await page.$eval(getSelector("353R"), el => el.disabled); + expect(readonly).withContext(`In ${browserName}`).toEqual(true); + checked = await page.$eval(getSelector("353R"), el => el.checked); + expect(checked).withContext(`In ${browserName}`).toEqual(false); + }) + ); + }); + }); }); diff --git a/test/pdfs/issue16863.pdf.link b/test/pdfs/issue16863.pdf.link new file mode 100644 index 000000000..e30dbf5ca --- /dev/null +++ b/test/pdfs/issue16863.pdf.link @@ -0,0 +1 @@ +https://github.com/mozilla/pdf.js/files/12422360/4422-84.pdf diff --git a/test/test_manifest.json b/test/test_manifest.json index e6ee8120e..1692017b4 100644 --- a/test/test_manifest.json +++ b/test/test_manifest.json @@ -8119,5 +8119,12 @@ "rotation": 0 } } + }, + { + "id": "issue16863", + "file": "pdfs/issue16863.pdf", + "md5": "af8abe281721f92a0d46646969f061de", + "link": true, + "type": "other" } ]