Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Empty fields are 0 when using AFSimple_Calculate #18552

Merged
merged 1 commit into from
Aug 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.