diff --git a/src/core/annotation.js b/src/core/annotation.js index c66305d9e3ada..2848776f00335 100644 --- a/src/core/annotation.js +++ b/src/core/annotation.js @@ -2007,7 +2007,7 @@ class ButtonWidgetAnnotation extends WidgetAnnotation { } return { id: this.data.id, - value: this.data.fieldValue || null, + value: this.data.fieldValue || "Off", defaultValue: this.data.defaultFieldValue, exportValues, editable: !this.data.readOnly, diff --git a/src/display/annotation_layer.js b/src/display/annotation_layer.js index 5d2462d8aa13f..25a8fda525673 100644 --- a/src/display/annotation_layer.js +++ b/src/display/annotation_layer.js @@ -544,9 +544,6 @@ class WidgetAnnotationElement extends AnnotationElement { } _setEventListener(element, baseName, eventName, valueGetter) { - if (this.data.actions[eventName.replace(" ", "")] === undefined) { - return; - } if (baseName.includes("mouse")) { // Mouse events element.addEventListener(baseName, event => { @@ -577,11 +574,14 @@ class WidgetAnnotationElement extends AnnotationElement { } _setEventListeners(element, names, getter) { - if (!this.data.actions) { - return; - } for (const [baseName, eventName] of names) { - this._setEventListener(element, baseName, eventName, getter); + if ( + eventName === "Action" || + (this.data.actions && + this.data.actions[eventName.replace(" ", "")] !== undefined) + ) { + this._setEventListener(element, baseName, eventName, getter); + } } } } diff --git a/test/integration/scripting_spec.js b/test/integration/scripting_spec.js index 1b6d94bfff65c..ec3d50026296e 100644 --- a/test/integration/scripting_spec.js +++ b/test/integration/scripting_spec.js @@ -218,20 +218,20 @@ describe("Interaction", () => { ); const expected = [ - ["#\\36 8R", "Group1=Choice1::1"], - ["#\\36 9R", "Group1=Choice2::2"], - ["#\\37 0R", "Group1=Choice3::3"], - ["#\\37 1R", "Group1=Choice4::4"], + ["#\\38 1R", "Group1=Choice1::1"], + ["#\\38 2R", "Group1=Choice2::2"], + ["#\\38 3R", "Group1=Choice3::3"], + ["#\\38 4R", "Group1=Choice4::4"], ]; for (const [selector, expectedText] of expected) { // Clear the textfield - await clearInput(page, "#\\36 7R"); + await clearInput(page, "#\\38 0R"); await page.click(selector); await page.waitForFunction( - `document.querySelector("#\\\\36 7R").value !== ""` + `document.querySelector("#\\\\38 0R").value !== ""` ); - const text = await page.$eval("#\\36 7R", el => el.value); + const text = await page.$eval("#\\38 0R", el => el.value); expect(text).withContext(`In ${browserName}`).toEqual(expectedText); } }) @@ -242,24 +242,24 @@ describe("Interaction", () => { await Promise.all( pages.map(async ([browserName, page]) => { const expected = [ - ["#\\37 2R", "Check1=Yes::5"], - ["#\\37 4R", "Check2=Yes::6"], - ["#\\37 5R", "Check3=Yes::7"], - ["#\\37 6R", "Check4=Yes::8"], - ["#\\37 2R", "Check1=Off::5"], - ["#\\37 4R", "Check2=Off::6"], - ["#\\37 5R", "Check3=Off::7"], - ["#\\37 6R", "Check4=Off::8"], + ["#\\38 5R", "Check1=Yes::5"], + ["#\\38 7R", "Check2=Yes::6"], + ["#\\38 8R", "Check3=Yes::7"], + ["#\\38 9R", "Check4=Yes::8"], + ["#\\38 5R", "Check1=Off::5"], + ["#\\38 7R", "Check2=Off::6"], + ["#\\38 8R", "Check3=Off::7"], + ["#\\38 9R", "Check4=Off::8"], ]; for (const [selector, expectedText] of expected) { // Clear the textfield - await clearInput(page, "#\\36 7R"); + await clearInput(page, "#\\38 0R"); await page.click(selector); await page.waitForFunction( - `document.querySelector("#\\\\36 7R").value !== ""` + `document.querySelector("#\\\\38 0R").value !== ""` ); - const text = await page.$eval("#\\36 7R", el => el.value); + const text = await page.$eval("#\\38 0R", el => el.value); expect(text).withContext(`In ${browserName}`).toEqual(expectedText); } }) @@ -270,21 +270,51 @@ describe("Interaction", () => { await Promise.all( pages.map(async ([browserName, page]) => { const expected = [ - ["#\\37 7R", "Check5=Yes1::9"], - ["#\\37 8R", "Check5=Yes2::10"], - ["#\\37 9R", "Check5=Yes3::11"], - ["#\\38 0R", "Check5=Yes4::12"], - ["#\\38 0R", "Check5=Off::12"], + ["#\\39 0R", "Check5=Yes1::9"], + ["#\\39 1R", "Check5=Yes2::10"], + ["#\\39 2R", "Check5=Yes3::11"], + ["#\\39 3R", "Check5=Yes4::12"], + ["#\\39 3R", "Check5=Off::12"], ]; for (const [selector, expectedText] of expected) { // Clear the textfield - await clearInput(page, "#\\36 7R"); + await clearInput(page, "#\\38 0R"); await page.click(selector); await page.waitForFunction( - `document.querySelector("#\\\\36 7R").value !== ""` + `document.querySelector("#\\\\38 0R").value !== ""` ); - const text = await page.$eval("#\\36 7R", el => el.value); + const text = await page.$eval("#\\38 0R", el => el.value); + expect(text).withContext(`In ${browserName}`).toEqual(expectedText); + } + }) + ); + }); + + it("must show values in a text input when clicking on checkboxes or radio with no actions", async () => { + await Promise.all( + pages.map(async ([browserName, page]) => { + const expected = [ + ["", "Off;Off"], + ["#\\39 4R", "Yes;Off"], + ["#\\39 5R", "Yes;NoAct2"], + ["#\\39 6R", "Yes;NoAct3"], + ["#\\39 4R", "Off;NoAct3"], + ["#\\39 5R", "Off;NoAct2"], + ]; + for (const [selector, expectedText] of expected) { + // Clear the textfield + await clearInput(page, "#\\38 0R"); + + if (selector) { + await page.click(selector); + } + + await page.click("[data-annotation-id='97R']"); + await page.waitForFunction( + `document.querySelector("#\\\\38 0R").value !== ""` + ); + const text = await page.$eval("#\\38 0R", el => el.value); expect(text).withContext(`In ${browserName}`).toEqual(expectedText); } }) diff --git a/test/pdfs/js-buttons.pdf b/test/pdfs/js-buttons.pdf index 4238249b91dad..a839176de1a39 100644 Binary files a/test/pdfs/js-buttons.pdf and b/test/pdfs/js-buttons.pdf differ diff --git a/test/test_manifest.json b/test/test_manifest.json index 55abbdfcb6b06..29cd2ac475360 100644 --- a/test/test_manifest.json +++ b/test/test_manifest.json @@ -4338,7 +4338,7 @@ }, { "id": "js-buttons", "file": "pdfs/js-buttons.pdf", - "md5": "2c56d419c1fb533349fd1ddef3f14da6", + "md5": "26f552398b77f8e85b2a8a166ca2ba6a", "rounds": 1, "type": "eq" },