diff --git a/src/core/xfa/template.js b/src/core/xfa/template.js index 5fa05df53..31f43537f 100644 --- a/src/core/xfa/template.js +++ b/src/core/xfa/template.js @@ -2405,6 +2405,10 @@ class Field extends XFAObject { value = htmlValue.value; } } + if (this.ui.textEdit && this.value.text && this.value.text.maxChars) { + ui.children[0].attributes.maxLength = this.value.text.maxChars; + } + if (value) { if (ui.children[0].name === "textarea") { ui.children[0].attributes.textContent = value; diff --git a/test/unit/xfa_tohtml_spec.js b/test/unit/xfa_tohtml_spec.js index d0b3278c8..14bc28da6 100644 --- a/test/unit/xfa_tohtml_spec.js +++ b/test/unit/xfa_tohtml_spec.js @@ -16,6 +16,22 @@ import { XFAFactory } from "../../src/core/xfa/factory.js"; describe("XFAFactory", function () { + function searchHtmlNode(root, name, value) { + if (root[name] === value) { + return root; + } + if (!root.children) { + return null; + } + for (const child of root.children) { + const node = searchHtmlNode(child, name, value); + if (node) { + return node; + } + } + return null; + } + describe("toHTML", function () { it("should convert some basic properties to CSS", function () { const xml = ` @@ -108,5 +124,45 @@ describe("XFAFactory", function () { pages.children[1].children[0].children[0].attributes.style ); }); + + it("should have a maxLength property", function () { + const xml = ` + + + + + + + + + `; + const factory = new XFAFactory({ "xdp:xdp": xml }); + + expect(factory.numberPages).toEqual(1); + + const pages = factory.getPages(); + const field = searchHtmlNode(pages, "name", "textarea"); + + expect(field.attributes.maxLength).toEqual(123); + }); }); });