Merge pull request #15757 from calixteman/bug1802888
[JS] By default, a text field value must be treated as a number (bug 1802888)
This commit is contained in:
commit
f96b99c30c
@ -80,7 +80,7 @@ class Field extends PDFObject {
|
|||||||
this._page = data.page || 0;
|
this._page = data.page || 0;
|
||||||
this._strokeColor = data.strokeColor || ["G", 0];
|
this._strokeColor = data.strokeColor || ["G", 0];
|
||||||
this._textColor = data.textColor || ["G", 0];
|
this._textColor = data.textColor || ["G", 0];
|
||||||
this._value = data.value || "";
|
this._value = null;
|
||||||
this._kidIds = data.kidIds || null;
|
this._kidIds = data.kidIds || null;
|
||||||
this._fieldType = getFieldType(this._actions);
|
this._fieldType = getFieldType(this._actions);
|
||||||
this._siblings = data.siblings || null;
|
this._siblings = data.siblings || null;
|
||||||
@ -88,6 +88,9 @@ class Field extends PDFObject {
|
|||||||
|
|
||||||
this._globalEval = data.globalEval;
|
this._globalEval = data.globalEval;
|
||||||
this._appObjects = data.appObjects;
|
this._appObjects = data.appObjects;
|
||||||
|
|
||||||
|
// The value is set depending on the field type.
|
||||||
|
this.value = data.value || "";
|
||||||
}
|
}
|
||||||
|
|
||||||
get currentValueIndices() {
|
get currentValueIndices() {
|
||||||
@ -243,12 +246,13 @@ class Field extends PDFObject {
|
|||||||
this._value = "";
|
this._value = "";
|
||||||
} else if (typeof value === "string") {
|
} else if (typeof value === "string") {
|
||||||
switch (this._fieldType) {
|
switch (this._fieldType) {
|
||||||
|
case FieldType.none:
|
||||||
|
this._value = !isNaN(value) ? parseFloat(value) : value;
|
||||||
|
break;
|
||||||
case FieldType.number:
|
case FieldType.number:
|
||||||
case FieldType.percent:
|
case FieldType.percent:
|
||||||
value = parseFloat(value);
|
const number = parseFloat(value);
|
||||||
if (!isNaN(value)) {
|
this._value = !isNaN(number) ? number : 0;
|
||||||
this._value = value;
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
this._value = value;
|
this._value = value;
|
||||||
@ -563,6 +567,9 @@ class RadioButtonField extends Field {
|
|||||||
this._id = radioData.id;
|
this._id = radioData.id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this._hasBeenInitialized = true;
|
||||||
|
this._value = data.value || "";
|
||||||
}
|
}
|
||||||
|
|
||||||
get value() {
|
get value() {
|
||||||
@ -570,6 +577,10 @@ class RadioButtonField extends Field {
|
|||||||
}
|
}
|
||||||
|
|
||||||
set value(value) {
|
set value(value) {
|
||||||
|
if (!this._hasBeenInitialized) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (value === null || value === undefined) {
|
if (value === null || value === undefined) {
|
||||||
this._value = "";
|
this._value = "";
|
||||||
}
|
}
|
||||||
|
@ -297,6 +297,7 @@ class Util extends PDFObject {
|
|||||||
|
|
||||||
printx(cFormat, cSource) {
|
printx(cFormat, cSource) {
|
||||||
// case
|
// case
|
||||||
|
cSource = (cSource ?? "").toString();
|
||||||
const handlers = [x => x, x => x.toUpperCase(), x => x.toLowerCase()];
|
const handlers = [x => x, x => x.toUpperCase(), x => x.toLowerCase()];
|
||||||
const buf = [];
|
const buf = [];
|
||||||
let i = 0;
|
let i = 0;
|
||||||
|
@ -1562,4 +1562,40 @@ describe("Interaction", () => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("in bug1802888.pdf", () => {
|
||||||
|
let pages;
|
||||||
|
|
||||||
|
beforeAll(async () => {
|
||||||
|
pages = await loadAndWait("bug1802888.pdf", getSelector("30R"));
|
||||||
|
});
|
||||||
|
|
||||||
|
afterAll(async () => {
|
||||||
|
await closePages(pages);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("must check field value is treated by default as a number", async () => {
|
||||||
|
await Promise.all(
|
||||||
|
pages.map(async ([browserName, page]) => {
|
||||||
|
await page.waitForFunction(
|
||||||
|
"window.PDFViewerApplication.scriptingReady === true"
|
||||||
|
);
|
||||||
|
|
||||||
|
await page.type(getSelector("30R"), "123", {
|
||||||
|
delay: 10,
|
||||||
|
});
|
||||||
|
await page.click(getSelector("31R"));
|
||||||
|
await page.type(getSelector("31R"), "456", {
|
||||||
|
delay: 10,
|
||||||
|
});
|
||||||
|
await page.click(getSelector("26R"));
|
||||||
|
await page.click(getSelector("27R"));
|
||||||
|
await page.waitForFunction(`${getQuerySelector("26R")}.value !== ""`);
|
||||||
|
|
||||||
|
const value = await page.$eval(getSelector("26R"), el => el.value);
|
||||||
|
expect(value).withContext(`In ${browserName}`).toEqual("579");
|
||||||
|
})
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
1
test/pdfs/.gitignore
vendored
1
test/pdfs/.gitignore
vendored
@ -556,3 +556,4 @@
|
|||||||
!textfields.pdf
|
!textfields.pdf
|
||||||
!freetext_no_appearance.pdf
|
!freetext_no_appearance.pdf
|
||||||
!issue15690.pdf
|
!issue15690.pdf
|
||||||
|
!bug1802888.pdf
|
||||||
|
BIN
test/pdfs/bug1802888.pdf
Executable file
BIN
test/pdfs/bug1802888.pdf
Executable file
Binary file not shown.
@ -346,7 +346,7 @@ describe("Scripting", function () {
|
|||||||
expect(send_queue.has(refId)).toEqual(true);
|
expect(send_queue.has(refId)).toEqual(true);
|
||||||
expect(send_queue.get(refId)).toEqual({
|
expect(send_queue.get(refId)).toEqual({
|
||||||
id: refId,
|
id: refId,
|
||||||
value: "123",
|
value: 123,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -826,7 +826,7 @@ describe("Scripting", function () {
|
|||||||
expect(send_queue.get(refId)).toEqual({
|
expect(send_queue.get(refId)).toEqual({
|
||||||
id: refId,
|
id: refId,
|
||||||
siblings: null,
|
siblings: null,
|
||||||
value: "123456.789",
|
value: 123456.789,
|
||||||
formattedValue: null,
|
formattedValue: null,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -1006,7 +1006,7 @@ describe("Scripting", function () {
|
|||||||
expect(send_queue.get(refId)).toEqual({
|
expect(send_queue.get(refId)).toEqual({
|
||||||
id: refId,
|
id: refId,
|
||||||
siblings: null,
|
siblings: null,
|
||||||
value: "321",
|
value: 321,
|
||||||
formattedValue: null,
|
formattedValue: null,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user