Skip to content

Commit c60c0d1

Browse files
authored
Merge pull request #18552 from calixteman/issue18536
Empty fields are 0 when using AFSimple_Calculate
2 parents 829c9f5 + 4b7f9a8 commit c60c0d1

File tree

4 files changed

+47
-4
lines changed

4 files changed

+47
-4
lines changed

src/scripting_api/aform.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -514,14 +514,12 @@ class AForm {
514514
}
515515
for (const child of field.getArray()) {
516516
const number = this.AFMakeNumber(child.value);
517-
if (number !== null) {
518-
values.push(number);
519-
}
517+
values.push(number ?? 0);
520518
}
521519
}
522520

523521
if (values.length === 0) {
524-
event.value = cFunction === "PRD" ? 1 : 0;
522+
event.value = 0;
525523
return;
526524
}
527525

test/integration/scripting_spec.mjs

+44
Original file line numberDiff line numberDiff line change
@@ -2466,4 +2466,48 @@ describe("Interaction", () => {
24662466
);
24672467
});
24682468
});
2469+
2470+
describe("Compute product of different fields", () => {
2471+
let pages;
2472+
let otherPages;
2473+
2474+
beforeAll(async () => {
2475+
otherPages = await Promise.all(
2476+
global.integrationSessions.map(async session =>
2477+
session.browser.newPage()
2478+
)
2479+
);
2480+
pages = await loadAndWait("issue18536.pdf", getSelector("34R"));
2481+
});
2482+
2483+
afterAll(async () => {
2484+
await closePages(pages);
2485+
await Promise.all(otherPages.map(page => page.close()));
2486+
});
2487+
2488+
it("must check that the product are null", async () => {
2489+
await Promise.all(
2490+
pages.map(async ([browserName, page], i) => {
2491+
await waitForScripting(page);
2492+
2493+
const inputSelector = getSelector("34R");
2494+
await page.click(inputSelector);
2495+
await page.type(inputSelector, "123");
2496+
await page.click(getSelector("28R"));
2497+
await page.waitForFunction(
2498+
`${getQuerySelector("36R")}.value !== "0"`
2499+
);
2500+
2501+
let text = await page.$eval(getSelector("30R"), el => el.value);
2502+
expect(text).withContext(`In ${browserName}`).toEqual("0");
2503+
2504+
text = await page.$eval(getSelector("35R"), el => el.value);
2505+
expect(text).withContext(`In ${browserName}`).toEqual("0");
2506+
2507+
text = await page.$eval(getSelector("36R"), el => el.value);
2508+
expect(text).withContext(`In ${browserName}`).toEqual("123");
2509+
})
2510+
);
2511+
});
2512+
});
24692513
});

test/pdfs/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -659,3 +659,4 @@
659659
!issue18360.pdf
660660
!issue18099_reduced.pdf
661661
!file_pdfjs_test.pdf
662+
!issue18536.pdf

test/pdfs/issue18536.pdf

8.16 KB
Binary file not shown.

0 commit comments

Comments
 (0)