diff --git a/src/scripting_api/field.js b/src/scripting_api/field.js index 816824ce980e4..0188d484492f6 100644 --- a/src/scripting_api/field.js +++ b/src/scripting_api/field.js @@ -587,6 +587,12 @@ class RadioButtonField extends Field { this._value = data.value || ""; } + get _siblings() { + return this._radioIds.filter(id => id !== this._id); + } + + set _siblings(_) {} + get value() { return this._value; } diff --git a/src/scripting_api/initialization.js b/src/scripting_api/initialization.js index be941ed0cd715..946e6804862c7 100644 --- a/src/scripting_api/initialization.js +++ b/src/scripting_api/initialization.js @@ -96,27 +96,22 @@ function initSandbox(params) { obj.fieldPath = name; obj.appObjects = appObjects; + const otherFields = annotations.slice(1); + let field; switch (obj.type) { case "radiobutton": { - const otherButtons = annotations.slice(1); - field = new RadioButtonField(otherButtons, obj); + field = new RadioButtonField(otherFields, obj); break; } case "checkbox": { - const otherButtons = annotations.slice(1); - field = new CheckboxField(otherButtons, obj); + field = new CheckboxField(otherFields, obj); break; } - case "text": - if (annotations.length <= 1) { - field = new Field(obj); - break; - } - obj.siblings = annotations.map(x => x.id).slice(1); - field = new Field(obj); - break; default: + if (otherFields.length > 0) { + obj.siblings = otherFields.map(x => x.id); + } field = new Field(obj); } diff --git a/test/integration/scripting_spec.mjs b/test/integration/scripting_spec.mjs index 1de6f2195a254..715857f7022f3 100644 --- a/test/integration/scripting_spec.mjs +++ b/test/integration/scripting_spec.mjs @@ -2499,4 +2499,47 @@ describe("Interaction", () => { ); }); }); + + describe("Change radio property", () => { + let pages; + + beforeAll(async () => { + pages = await loadAndWait("bug1922766.pdf", "[data-annotation-id='44R']"); + }); + + afterAll(async () => { + await closePages(pages); + }); + + it("must check that a change on a radio implies the change on all the radio in the group", async () => { + await Promise.all( + pages.map(async ([browserName, page]) => { + await waitForScripting(page); + + const checkColor = async color => { + await waitForSandboxTrip(page); + for (const i of [40, 41, 42, 43]) { + const bgColor = await page.$eval( + `[data-element-id='${i}R']`, + el => getComputedStyle(el).backgroundColor + ); + expect(bgColor) + .withContext(`In ${browserName}`) + .toEqual(`rgb(${color.join(", ")})`); + } + }; + await checkColor([255, 0, 0]); + await page.click("[data-annotation-id='44R']"); + await checkColor([0, 0, 255]); + await page.click("[data-annotation-id='44R']"); + await checkColor([255, 0, 0]); + + await page.click("[data-annotation-id='43R']"); + await waitForSandboxTrip(page); + await page.click("[data-annotation-id='44R']"); + await checkColor([0, 0, 255]); + }) + ); + }); + }); }); diff --git a/test/pdfs/.gitignore b/test/pdfs/.gitignore index 65914dcf14e5d..7af1f403d887e 100644 --- a/test/pdfs/.gitignore +++ b/test/pdfs/.gitignore @@ -678,3 +678,4 @@ !issue15096.pdf !issue18036.pdf !issue18894.pdf +!bug1922766.pdf diff --git a/test/pdfs/bug1922766.pdf b/test/pdfs/bug1922766.pdf new file mode 100755 index 0000000000000..f6aeed980df91 Binary files /dev/null and b/test/pdfs/bug1922766.pdf differ