Use the original value of a field when propagating event (fixes #17540)
And avoid to not format a field when the value is 0.
This commit is contained in:
parent
f8e3c79cb5
commit
5732c0c54a
@ -220,10 +220,6 @@ class AForm {
|
|||||||
bCurrencyPrepend
|
bCurrencyPrepend
|
||||||
) {
|
) {
|
||||||
const event = globalThis.event;
|
const event = globalThis.event;
|
||||||
if (!event.value) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
let value = this.AFMakeNumber(event.value);
|
let value = this.AFMakeNumber(event.value);
|
||||||
if (value === null) {
|
if (value === null) {
|
||||||
event.value = "";
|
event.value = "";
|
||||||
|
@ -335,7 +335,7 @@ class EventDispatcher {
|
|||||||
|
|
||||||
event.value = null;
|
event.value = null;
|
||||||
const target = this._objects[targetId];
|
const target = this._objects[targetId];
|
||||||
let savedValue = target.obj.value;
|
let savedValue = target.obj._getValue();
|
||||||
this.runActions(source, target, event, "Calculate");
|
this.runActions(source, target, event, "Calculate");
|
||||||
if (!event.rc) {
|
if (!event.rc) {
|
||||||
continue;
|
continue;
|
||||||
@ -344,18 +344,23 @@ class EventDispatcher {
|
|||||||
if (event.value !== null) {
|
if (event.value !== null) {
|
||||||
// A new value has been calculated so set it.
|
// A new value has been calculated so set it.
|
||||||
target.obj.value = event.value;
|
target.obj.value = event.value;
|
||||||
|
} else {
|
||||||
|
event.value = target.obj._getValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
event.value = target.obj.value;
|
|
||||||
this.runActions(target, target, event, "Validate");
|
this.runActions(target, target, event, "Validate");
|
||||||
if (!event.rc) {
|
if (!event.rc) {
|
||||||
if (target.obj.value !== savedValue) {
|
if (target.obj._getValue() !== savedValue) {
|
||||||
target.wrapped.value = savedValue;
|
target.wrapped.value = savedValue;
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
savedValue = event.value = target.obj.value;
|
if (event.value === null) {
|
||||||
|
event.value = target.obj._getValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
savedValue = target.obj._getValue();
|
||||||
let formattedValue = null;
|
let formattedValue = null;
|
||||||
if (this.runActions(target, target, event, "Format")) {
|
if (this.runActions(target, target, event, "Format")) {
|
||||||
formattedValue = event.value?.toString?.();
|
formattedValue = event.value?.toString?.();
|
||||||
|
@ -2324,4 +2324,46 @@ describe("Interaction", () => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("Textfield with a number and some decimals", () => {
|
||||||
|
let pages;
|
||||||
|
let otherPages;
|
||||||
|
|
||||||
|
beforeAll(async () => {
|
||||||
|
otherPages = await Promise.all(
|
||||||
|
global.integrationSessions.map(async session =>
|
||||||
|
session.browser.newPage()
|
||||||
|
)
|
||||||
|
);
|
||||||
|
pages = await loadAndWait("issue17540.pdf", getSelector("15R"));
|
||||||
|
});
|
||||||
|
|
||||||
|
afterAll(async () => {
|
||||||
|
await closePages(pages);
|
||||||
|
await Promise.all(otherPages.map(page => page.close()));
|
||||||
|
});
|
||||||
|
|
||||||
|
it("must check the number has the correct number of decimals", async () => {
|
||||||
|
await Promise.all(
|
||||||
|
pages.map(async ([browserName, page], i) => {
|
||||||
|
await page.waitForFunction(
|
||||||
|
"window.PDFViewerApplication.scriptingReady === true"
|
||||||
|
);
|
||||||
|
|
||||||
|
await page.click(getSelector("15R"));
|
||||||
|
await page.type(getSelector("15R"), "3");
|
||||||
|
await page.keyboard.press("Enter");
|
||||||
|
|
||||||
|
await page.waitForFunction(
|
||||||
|
sel => document.querySelector(sel).value !== "",
|
||||||
|
{},
|
||||||
|
getSelector("16R")
|
||||||
|
);
|
||||||
|
|
||||||
|
const text = await page.$eval(getSelector("16R"), el => el.value);
|
||||||
|
expect(text).withContext(`In ${browserName}`).toEqual("0.900");
|
||||||
|
})
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
1
test/pdfs/.gitignore
vendored
1
test/pdfs/.gitignore
vendored
@ -625,3 +625,4 @@
|
|||||||
!bug1871353.1.pdf
|
!bug1871353.1.pdf
|
||||||
!file_pdfjs_form.pdf
|
!file_pdfjs_form.pdf
|
||||||
!issue17492.pdf
|
!issue17492.pdf
|
||||||
|
!issue17540.pdf
|
||||||
|
BIN
test/pdfs/issue17540.pdf
Normal file
BIN
test/pdfs/issue17540.pdf
Normal file
Binary file not shown.
@ -716,6 +716,11 @@ describe("Scripting", function () {
|
|||||||
`AFNumber_Format(2, 0, 3, 0, "€", false);` +
|
`AFNumber_Format(2, 0, 3, 0, "€", false);` +
|
||||||
`event.source.value = event.value;`,
|
`event.source.value = event.value;`,
|
||||||
],
|
],
|
||||||
|
test6: [
|
||||||
|
`event.value = 0;` +
|
||||||
|
`AFNumber_Format(2, 0, 0, 0, "€", false);` +
|
||||||
|
`event.source.value = event.value;`,
|
||||||
|
],
|
||||||
},
|
},
|
||||||
type: "text",
|
type: "text",
|
||||||
},
|
},
|
||||||
@ -727,6 +732,30 @@ describe("Scripting", function () {
|
|||||||
};
|
};
|
||||||
|
|
||||||
sandbox.createSandbox(data);
|
sandbox.createSandbox(data);
|
||||||
|
await sandbox.dispatchEventInSandbox({
|
||||||
|
id: refId,
|
||||||
|
value: "0",
|
||||||
|
name: "test1",
|
||||||
|
});
|
||||||
|
expect(send_queue.has(refId)).toEqual(true);
|
||||||
|
expect(send_queue.get(refId)).toEqual({
|
||||||
|
id: refId,
|
||||||
|
value: "0.00€",
|
||||||
|
});
|
||||||
|
send_queue.delete(refId);
|
||||||
|
|
||||||
|
await sandbox.dispatchEventInSandbox({
|
||||||
|
id: refId,
|
||||||
|
value: "",
|
||||||
|
name: "test6",
|
||||||
|
});
|
||||||
|
expect(send_queue.has(refId)).toEqual(true);
|
||||||
|
expect(send_queue.get(refId)).toEqual({
|
||||||
|
id: refId,
|
||||||
|
value: "0.00€",
|
||||||
|
});
|
||||||
|
send_queue.delete(refId);
|
||||||
|
|
||||||
await sandbox.dispatchEventInSandbox({
|
await sandbox.dispatchEventInSandbox({
|
||||||
id: refId,
|
id: refId,
|
||||||
value: "123456.789",
|
value: "123456.789",
|
||||||
|
Loading…
Reference in New Issue
Block a user