Skip to content

Commit 246d565

Browse files
authored
Merge pull request #13559 from calixteman/maxlength
XFA - Handle maxChars property for text fields
2 parents 9d081d0 + d89c429 commit 246d565

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed

src/core/xfa/template.js

+4
Original file line numberDiff line numberDiff line change
@@ -2405,6 +2405,10 @@ class Field extends XFAObject {
24052405
value = htmlValue.value;
24062406
}
24072407
}
2408+
if (this.ui.textEdit && this.value.text && this.value.text.maxChars) {
2409+
ui.children[0].attributes.maxLength = this.value.text.maxChars;
2410+
}
2411+
24082412
if (value) {
24092413
if (ui.children[0].name === "textarea") {
24102414
ui.children[0].attributes.textContent = value;

test/unit/xfa_tohtml_spec.js

+56
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,22 @@
1616
import { XFAFactory } from "../../src/core/xfa/factory.js";
1717

1818
describe("XFAFactory", function () {
19+
function searchHtmlNode(root, name, value) {
20+
if (root[name] === value) {
21+
return root;
22+
}
23+
if (!root.children) {
24+
return null;
25+
}
26+
for (const child of root.children) {
27+
const node = searchHtmlNode(child, name, value);
28+
if (node) {
29+
return node;
30+
}
31+
}
32+
return null;
33+
}
34+
1935
describe("toHTML", function () {
2036
it("should convert some basic properties to CSS", function () {
2137
const xml = `
@@ -108,5 +124,45 @@ describe("XFAFactory", function () {
108124
pages.children[1].children[0].children[0].attributes.style
109125
);
110126
});
127+
128+
it("should have a maxLength property", function () {
129+
const xml = `
130+
<?xml version="1.0"?>
131+
<xdp:xdp xmlns:xdp="http://ns.adobe.com/xdp/">
132+
<template xmlns="http://www.xfa.org/schema/xfa-template/3.3">
133+
<subform name="root" mergeMode="matchTemplate">
134+
<pageSet>
135+
<pageArea>
136+
<contentArea x="123pt" w="456pt" h="789pt"/>
137+
<medium stock="default" short="456pt" long="789pt"/>
138+
<field y="1pt" w="11pt" h="22pt" x="2pt">
139+
<ui>
140+
<textEdit/>
141+
</ui>
142+
<value>
143+
<text maxChars="123"/>
144+
</value>
145+
</field>
146+
</pageArea>
147+
</pageSet>
148+
<subform name="first">
149+
</subform>
150+
</subform>
151+
</template>
152+
<xfa:datasets xmlns:xfa="http://www.xfa.org/schema/xfa-data/1.0/">
153+
<xfa:data>
154+
</xfa:data>
155+
</xfa:datasets>
156+
</xdp:xdp>
157+
`;
158+
const factory = new XFAFactory({ "xdp:xdp": xml });
159+
160+
expect(factory.numberPages).toEqual(1);
161+
162+
const pages = factory.getPages();
163+
const field = searchHtmlNode(pages, "name", "textarea");
164+
165+
expect(field.attributes.maxLength).toEqual(123);
166+
});
111167
});
112168
});

0 commit comments

Comments
 (0)