Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When changing a property on a radio button then change it for the siblings (bug 1922766) #18916

Merged
merged 1 commit into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/scripting_api/field.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
19 changes: 7 additions & 12 deletions src/scripting_api/initialization.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
43 changes: 43 additions & 0 deletions test/integration/scripting_spec.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
})
);
});
});
});
1 change: 1 addition & 0 deletions test/pdfs/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -678,3 +678,4 @@
!issue15096.pdf
!issue18036.pdf
!issue18894.pdf
!bug1922766.pdf
Binary file added test/pdfs/bug1922766.pdf
Binary file not shown.