Skip to content

Commit

Permalink
Empty fields are 0 when using AFSimple_Calculate
Browse files Browse the repository at this point in the history
  • Loading branch information
calixteman committed Aug 2, 2024
1 parent a372bf8 commit 4b7f9a8
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 4 deletions.
6 changes: 2 additions & 4 deletions src/scripting_api/aform.js
Original file line number Diff line number Diff line change
Expand Up @@ -514,14 +514,12 @@ class AForm {
}
for (const child of field.getArray()) {
const number = this.AFMakeNumber(child.value);
if (number !== null) {
values.push(number);
}
values.push(number ?? 0);
}
}

if (values.length === 0) {
event.value = cFunction === "PRD" ? 1 : 0;
event.value = 0;
return;
}

Expand Down
44 changes: 44 additions & 0 deletions test/integration/scripting_spec.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
})
);
});
});
});
1 change: 1 addition & 0 deletions test/pdfs/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -659,3 +659,4 @@
!issue18360.pdf
!issue18099_reduced.pdf
!file_pdfjs_test.pdf
!issue18536.pdf
Binary file added test/pdfs/issue18536.pdf
Binary file not shown.

0 comments on commit 4b7f9a8

Please sign in to comment.