Skip to content

Commit 7b4fa0a

Browse files
authored
Merge pull request #13540 from calixteman/13536
XFA - Return html element for the different possible value
2 parents 950dcc7 + 367d1ad commit 7b4fa0a

File tree

1 file changed

+29
-22
lines changed

1 file changed

+29
-22
lines changed

src/core/xfa/template.js

+29-22
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,17 @@ function getRoot(node) {
106106
return parent;
107107
}
108108

109+
function valueToHtml(value) {
110+
return HTMLResult.success({
111+
name: "span",
112+
attributes: {
113+
class: ["xfaRich"],
114+
style: Object.create(null),
115+
},
116+
value,
117+
});
118+
}
119+
109120
function getTransformedBBox(node) {
110121
// Take into account rotation and anchor the get the
111122
// real bounding box.
@@ -615,7 +626,7 @@ class BooleanElement extends Option01 {
615626
}
616627

617628
[$toHTML](availableSpace) {
618-
return HTMLResult.success(this[$content] === 1);
629+
return valueToHtml(this[$content] === 1);
619630
}
620631
}
621632

@@ -1257,11 +1268,12 @@ class DateElement extends ContentObject {
12571268
}
12581269

12591270
[$finalize]() {
1260-
this[$content] = new Date(this[$content].trim());
1271+
const date = this[$content].trim();
1272+
this[$content] = date ? new Date(date) : null;
12611273
}
12621274

12631275
[$toHTML](availableSpace) {
1264-
return HTMLResult.success(this[$content].toString());
1276+
return valueToHtml(this[$content] ? this[$content].toString() : "");
12651277
}
12661278
}
12671279

@@ -1275,11 +1287,12 @@ class DateTime extends ContentObject {
12751287
}
12761288

12771289
[$finalize]() {
1278-
this[$content] = new Date(this[$content].trim());
1290+
const date = this[$content].trim();
1291+
this[$content] = date ? new Date(date) : null;
12791292
}
12801293

12811294
[$toHTML](availableSpace) {
1282-
return HTMLResult.success(this[$content].toString());
1295+
return valueToHtml(this[$content] ? this[$content].toString() : "");
12831296
}
12841297
}
12851298

@@ -1351,7 +1364,7 @@ class Decimal extends ContentObject {
13511364
}
13521365

13531366
[$toHTML](availableSpace) {
1354-
return HTMLResult.success(
1367+
return valueToHtml(
13551368
this[$content] !== null ? this[$content].toString() : ""
13561369
);
13571370
}
@@ -2365,12 +2378,12 @@ class Field extends XFAObject {
23652378
if (this.ui.imageEdit) {
23662379
ui.children.push(this.value[$toHTML]().html);
23672380
} else if (!this.ui.button) {
2368-
const value = this.value[$toHTML]().html;
2381+
const value = this.value[$toHTML]().html.value;
23692382
if (value) {
23702383
if (ui.children[0].name === "textarea") {
2371-
ui.children[0].attributes.textContent = value.value;
2384+
ui.children[0].attributes.textContent = value;
23722385
} else {
2373-
ui.children[0].attributes.value = value.value;
2386+
ui.children[0].attributes.value = value;
23742387
}
23752388
}
23762389
}
@@ -2522,7 +2535,7 @@ class Float extends ContentObject {
25222535
}
25232536

25242537
[$toHTML](availableSpace) {
2525-
return HTMLResult.success(
2538+
return valueToHtml(
25262539
this[$content] !== null ? this[$content].toString() : ""
25272540
);
25282541
}
@@ -2812,7 +2825,7 @@ class Integer extends ContentObject {
28122825
}
28132826

28142827
[$toHTML](availableSpace) {
2815-
return HTMLResult.success(
2828+
return valueToHtml(
28162829
this[$content] !== null ? this[$content].toString() : ""
28172830
);
28182831
}
@@ -4642,14 +4655,7 @@ class Text extends ContentObject {
46424655
if (typeof this[$content] === "string") {
46434656
// \u2028 is a line separator.
46444657
// \u2029 is a paragraph separator.
4645-
const html = {
4646-
name: "span",
4647-
attributes: {
4648-
class: ["xfaRich"],
4649-
style: {},
4650-
},
4651-
value: this[$content],
4652-
};
4658+
const html = valueToHtml(this[$content]).html;
46534659

46544660
if (this[$content].includes("\u2029")) {
46554661
// We've plain text containing a paragraph separator
@@ -4782,12 +4788,13 @@ class Time extends StringObject {
47824788
}
47834789

47844790
[$finalize]() {
4785-
// TODO
4786-
this[$content] = new Date(this[$content]);
4791+
// TODO: need to handle the string as a time and not as a date.
4792+
const date = this[$content].trim();
4793+
this[$content] = date ? new Date(date) : null;
47874794
}
47884795

47894796
[$toHTML](availableSpace) {
4790-
return HTMLResult.success(this[$content].toString());
4797+
return valueToHtml(this[$content] ? this[$content].toString() : "");
47914798
}
47924799
}
47934800

0 commit comments

Comments
 (0)