JS -- update radio/checkbox values even if there are no actions

This commit is contained in:
Calixte Denizet 2021-01-08 16:43:16 +01:00
parent 35845d1bbb
commit 7172f0a928
5 changed files with 65 additions and 35 deletions

View File

@ -1986,7 +1986,7 @@ class ButtonWidgetAnnotation extends WidgetAnnotation {
} }
return { return {
id: this.data.id, id: this.data.id,
value: this.data.fieldValue || null, value: this.data.fieldValue || "Off",
defaultValue: this.data.defaultFieldValue, defaultValue: this.data.defaultFieldValue,
exportValues, exportValues,
editable: !this.data.readOnly, editable: !this.data.readOnly,

View File

@ -544,9 +544,6 @@ class WidgetAnnotationElement extends AnnotationElement {
} }
_setEventListener(element, baseName, eventName, valueGetter) { _setEventListener(element, baseName, eventName, valueGetter) {
if (this.data.actions[eventName.replace(" ", "")] === undefined) {
return;
}
if (baseName.includes("mouse")) { if (baseName.includes("mouse")) {
// Mouse events // Mouse events
element.addEventListener(baseName, event => { element.addEventListener(baseName, event => {
@ -577,11 +574,14 @@ class WidgetAnnotationElement extends AnnotationElement {
} }
_setEventListeners(element, names, getter) { _setEventListeners(element, names, getter) {
if (!this.data.actions) {
return;
}
for (const [baseName, eventName] of names) { 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);
}
} }
} }
} }

View File

@ -218,20 +218,20 @@ describe("Interaction", () => {
); );
const expected = [ const expected = [
["#\\36 8R", "Group1=Choice1::1"], ["#\\38 1R", "Group1=Choice1::1"],
["#\\36 9R", "Group1=Choice2::2"], ["#\\38 2R", "Group1=Choice2::2"],
["#\\37 0R", "Group1=Choice3::3"], ["#\\38 3R", "Group1=Choice3::3"],
["#\\37 1R", "Group1=Choice4::4"], ["#\\38 4R", "Group1=Choice4::4"],
]; ];
for (const [selector, expectedText] of expected) { for (const [selector, expectedText] of expected) {
// Clear the textfield // Clear the textfield
await clearInput(page, "#\\36 7R"); await clearInput(page, "#\\38 0R");
await page.click(selector); await page.click(selector);
await page.waitForFunction( 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); expect(text).withContext(`In ${browserName}`).toEqual(expectedText);
} }
}) })
@ -242,24 +242,24 @@ describe("Interaction", () => {
await Promise.all( await Promise.all(
pages.map(async ([browserName, page]) => { pages.map(async ([browserName, page]) => {
const expected = [ const expected = [
["#\\37 2R", "Check1=Yes::5"], ["#\\38 5R", "Check1=Yes::5"],
["#\\37 4R", "Check2=Yes::6"], ["#\\38 7R", "Check2=Yes::6"],
["#\\37 5R", "Check3=Yes::7"], ["#\\38 8R", "Check3=Yes::7"],
["#\\37 6R", "Check4=Yes::8"], ["#\\38 9R", "Check4=Yes::8"],
["#\\37 2R", "Check1=Off::5"], ["#\\38 5R", "Check1=Off::5"],
["#\\37 4R", "Check2=Off::6"], ["#\\38 7R", "Check2=Off::6"],
["#\\37 5R", "Check3=Off::7"], ["#\\38 8R", "Check3=Off::7"],
["#\\37 6R", "Check4=Off::8"], ["#\\38 9R", "Check4=Off::8"],
]; ];
for (const [selector, expectedText] of expected) { for (const [selector, expectedText] of expected) {
// Clear the textfield // Clear the textfield
await clearInput(page, "#\\36 7R"); await clearInput(page, "#\\38 0R");
await page.click(selector); await page.click(selector);
await page.waitForFunction( 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); expect(text).withContext(`In ${browserName}`).toEqual(expectedText);
} }
}) })
@ -270,21 +270,51 @@ describe("Interaction", () => {
await Promise.all( await Promise.all(
pages.map(async ([browserName, page]) => { pages.map(async ([browserName, page]) => {
const expected = [ const expected = [
["#\\37 7R", "Check5=Yes1::9"], ["#\\39 0R", "Check5=Yes1::9"],
["#\\37 8R", "Check5=Yes2::10"], ["#\\39 1R", "Check5=Yes2::10"],
["#\\37 9R", "Check5=Yes3::11"], ["#\\39 2R", "Check5=Yes3::11"],
["#\\38 0R", "Check5=Yes4::12"], ["#\\39 3R", "Check5=Yes4::12"],
["#\\38 0R", "Check5=Off::12"], ["#\\39 3R", "Check5=Off::12"],
]; ];
for (const [selector, expectedText] of expected) { for (const [selector, expectedText] of expected) {
// Clear the textfield // Clear the textfield
await clearInput(page, "#\\36 7R"); await clearInput(page, "#\\38 0R");
await page.click(selector); await page.click(selector);
await page.waitForFunction( 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); expect(text).withContext(`In ${browserName}`).toEqual(expectedText);
} }
}) })

Binary file not shown.

View File

@ -4314,7 +4314,7 @@
}, },
{ "id": "js-buttons", { "id": "js-buttons",
"file": "pdfs/js-buttons.pdf", "file": "pdfs/js-buttons.pdf",
"md5": "2c56d419c1fb533349fd1ddef3f14da6", "md5": "26f552398b77f8e85b2a8a166ca2ba6a",
"rounds": 1, "rounds": 1,
"type": "eq" "type": "eq"
}, },