Merge pull request #13559 from calixteman/maxlength
XFA - Handle maxChars property for text fields
This commit is contained in:
commit
246d565e3b
@ -2405,6 +2405,10 @@ class Field extends XFAObject {
|
|||||||
value = htmlValue.value;
|
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 (value) {
|
||||||
if (ui.children[0].name === "textarea") {
|
if (ui.children[0].name === "textarea") {
|
||||||
ui.children[0].attributes.textContent = value;
|
ui.children[0].attributes.textContent = value;
|
||||||
|
@ -16,6 +16,22 @@
|
|||||||
import { XFAFactory } from "../../src/core/xfa/factory.js";
|
import { XFAFactory } from "../../src/core/xfa/factory.js";
|
||||||
|
|
||||||
describe("XFAFactory", function () {
|
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 () {
|
describe("toHTML", function () {
|
||||||
it("should convert some basic properties to CSS", function () {
|
it("should convert some basic properties to CSS", function () {
|
||||||
const xml = `
|
const xml = `
|
||||||
@ -108,5 +124,45 @@ describe("XFAFactory", function () {
|
|||||||
pages.children[1].children[0].children[0].attributes.style
|
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);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user