Merge pull request #13559 from calixteman/maxlength

XFA - Handle maxChars property for text fields
This commit is contained in:
calixteman 2021-06-14 14:21:04 +02:00 committed by GitHub
commit 246d565e3b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 60 additions and 0 deletions

View File

@ -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;

View File

@ -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 = `
<?xml version="1.0"?>
<xdp:xdp xmlns:xdp="http://ns.adobe.com/xdp/">
<template xmlns="http://www.xfa.org/schema/xfa-template/3.3">
<subform name="root" mergeMode="matchTemplate">
<pageSet>
<pageArea>
<contentArea x="123pt" w="456pt" h="789pt"/>
<medium stock="default" short="456pt" long="789pt"/>
<field y="1pt" w="11pt" h="22pt" x="2pt">
<ui>
<textEdit/>
</ui>
<value>
<text maxChars="123"/>
</value>
</field>
</pageArea>
</pageSet>
<subform name="first">
</subform>
</subform>
</template>
<xfa:datasets xmlns:xfa="http://www.xfa.org/schema/xfa-data/1.0/">
<xfa:data>
</xfa:data>
</xfa:datasets>
</xdp:xdp>
`;
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);
});
});
});