Empty fields are 0 when using AFSimple_Calculate

It fixes #18536 and #18532.
This commit is contained in:
Calixte Denizet 2024-08-02 21:49:00 +02:00
parent a372bf8f4d
commit 4b7f9a8d87
4 changed files with 47 additions and 4 deletions

View file

@ -514,14 +514,12 @@ class AForm {
} }
for (const child of field.getArray()) { for (const child of field.getArray()) {
const number = this.AFMakeNumber(child.value); const number = this.AFMakeNumber(child.value);
if (number !== null) { values.push(number ?? 0);
values.push(number);
}
} }
} }
if (values.length === 0) { if (values.length === 0) {
event.value = cFunction === "PRD" ? 1 : 0; event.value = 0;
return; return;
} }

View file

@ -2466,4 +2466,48 @@ describe("Interaction", () => {
); );
}); });
}); });
describe("Compute product of different fields", () => {
let pages;
let otherPages;
beforeAll(async () => {
otherPages = await Promise.all(
global.integrationSessions.map(async session =>
session.browser.newPage()
)
);
pages = await loadAndWait("issue18536.pdf", getSelector("34R"));
});
afterAll(async () => {
await closePages(pages);
await Promise.all(otherPages.map(page => page.close()));
});
it("must check that the product are null", async () => {
await Promise.all(
pages.map(async ([browserName, page], i) => {
await waitForScripting(page);
const inputSelector = getSelector("34R");
await page.click(inputSelector);
await page.type(inputSelector, "123");
await page.click(getSelector("28R"));
await page.waitForFunction(
`${getQuerySelector("36R")}.value !== "0"`
);
let text = await page.$eval(getSelector("30R"), el => el.value);
expect(text).withContext(`In ${browserName}`).toEqual("0");
text = await page.$eval(getSelector("35R"), el => el.value);
expect(text).withContext(`In ${browserName}`).toEqual("0");
text = await page.$eval(getSelector("36R"), el => el.value);
expect(text).withContext(`In ${browserName}`).toEqual("123");
})
);
});
});
}); });

View file

@ -659,3 +659,4 @@
!issue18360.pdf !issue18360.pdf
!issue18099_reduced.pdf !issue18099_reduced.pdf
!file_pdfjs_test.pdf !file_pdfjs_test.pdf
!issue18536.pdf

BIN
test/pdfs/issue18536.pdf Executable file

Binary file not shown.