mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-22 16:18:08 +02:00
[JS] By default, a text field value must be treated as a number (bug 1802888)
This commit is contained in:
parent
33f9d1aab2
commit
ae7da6ae48
6 changed files with 57 additions and 8 deletions
|
@ -80,7 +80,7 @@ class Field extends PDFObject {
|
|||
this._page = data.page || 0;
|
||||
this._strokeColor = data.strokeColor || ["G", 0];
|
||||
this._textColor = data.textColor || ["G", 0];
|
||||
this._value = data.value || "";
|
||||
this._value = null;
|
||||
this._kidIds = data.kidIds || null;
|
||||
this._fieldType = getFieldType(this._actions);
|
||||
this._siblings = data.siblings || null;
|
||||
|
@ -88,6 +88,9 @@ class Field extends PDFObject {
|
|||
|
||||
this._globalEval = data.globalEval;
|
||||
this._appObjects = data.appObjects;
|
||||
|
||||
// The value is set depending on the field type.
|
||||
this.value = data.value || "";
|
||||
}
|
||||
|
||||
get currentValueIndices() {
|
||||
|
@ -243,12 +246,13 @@ class Field extends PDFObject {
|
|||
this._value = "";
|
||||
} else if (typeof value === "string") {
|
||||
switch (this._fieldType) {
|
||||
case FieldType.none:
|
||||
this._value = !isNaN(value) ? parseFloat(value) : value;
|
||||
break;
|
||||
case FieldType.number:
|
||||
case FieldType.percent:
|
||||
value = parseFloat(value);
|
||||
if (!isNaN(value)) {
|
||||
this._value = value;
|
||||
}
|
||||
const number = parseFloat(value);
|
||||
this._value = !isNaN(number) ? number : 0;
|
||||
break;
|
||||
default:
|
||||
this._value = value;
|
||||
|
@ -563,6 +567,9 @@ class RadioButtonField extends Field {
|
|||
this._id = radioData.id;
|
||||
}
|
||||
}
|
||||
|
||||
this._hasBeenInitialized = true;
|
||||
this._value = data.value || "";
|
||||
}
|
||||
|
||||
get value() {
|
||||
|
@ -570,6 +577,10 @@ class RadioButtonField extends Field {
|
|||
}
|
||||
|
||||
set value(value) {
|
||||
if (!this._hasBeenInitialized) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (value === null || value === undefined) {
|
||||
this._value = "";
|
||||
}
|
||||
|
|
|
@ -297,6 +297,7 @@ class Util extends PDFObject {
|
|||
|
||||
printx(cFormat, cSource) {
|
||||
// case
|
||||
cSource = (cSource ?? "").toString();
|
||||
const handlers = [x => x, x => x.toUpperCase(), x => x.toLowerCase()];
|
||||
const buf = [];
|
||||
let i = 0;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue