Skip to content

Commit

Permalink
Merge pull request #12836 from calixteman/update_buttons
Browse files Browse the repository at this point in the history
JS -- update radio/checkbox values even if there are no actions
  • Loading branch information
brendandahl authored Jan 21, 2021
2 parents 1039698 + 7172f0a commit 2cba290
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 35 deletions.
2 changes: 1 addition & 1 deletion src/core/annotation.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
14 changes: 7 additions & 7 deletions src/display/annotation_layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down Expand Up @@ -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);
}
}
}
}
Expand Down
82 changes: 56 additions & 26 deletions test/integration/scripting_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
})
Expand All @@ -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);
}
})
Expand All @@ -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);
}
})
Expand Down
Binary file modified test/pdfs/js-buttons.pdf
Binary file not shown.
2 changes: 1 addition & 1 deletion test/test_manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -4338,7 +4338,7 @@
},
{ "id": "js-buttons",
"file": "pdfs/js-buttons.pdf",
"md5": "2c56d419c1fb533349fd1ddef3f14da6",
"md5": "26f552398b77f8e85b2a8a166ca2ba6a",
"rounds": 1,
"type": "eq"
},
Expand Down

0 comments on commit 2cba290

Please sign in to comment.