Skip to content

Commit

Permalink
Merge pull request #13570 from calixteman/xfa_field
Browse files Browse the repository at this point in the history
XFA - By default a text ui has only one line when in a field element
  • Loading branch information
calixteman authored Jun 17, 2021
2 parents d6deb95 + 793a015 commit 335d4cb
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 7 deletions.
18 changes: 13 additions & 5 deletions src/core/xfa/template.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
$addHTML,
$appendChild,
$childrenToHTML,
$clean,
$content,
$extra,
$finalize,
Expand Down Expand Up @@ -4820,11 +4821,7 @@ class TextEdit extends XFAObject {
"on",
]);
this.id = attributes.id || "";
this.multiLine = getInteger({
data: attributes.multiLine,
defaultValue: 1,
validate: x => x === 0,
});
this.multiLine = attributes.multiLine || "";
this.use = attributes.use || "";
this.usehref = attributes.usehref || "";
this.vScrollPolicy = getStringOption(attributes.vScrollPolicy, [
Expand All @@ -4838,6 +4835,17 @@ class TextEdit extends XFAObject {
this.margin = null;
}

[$clean](builder) {
super[$clean](builder);
const parent = this[$getParent]();
const defaultValue = parent instanceof Draw ? 1 : 0;
this.multiLine = getInteger({
data: this.multiLine,
defaultValue,
validate: x => x === 0 || x === 1,
});
}

[$toHTML](availableSpace) {
// TODO: incomplete.
const style = toStyle(this, "border", "font", "margin");
Expand Down
1 change: 1 addition & 0 deletions test/pdfs/xfa_bug1716809.pdf.link
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
https://bugzilla.mozilla.org/attachment.cgi?id=9227437
8 changes: 8 additions & 0 deletions test/test_manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -938,6 +938,14 @@
"enableXfa": true,
"type": "eq"
},
{ "id": "xfa_bug1716809",
"file": "pdfs/xfa_bug1716809.pdf",
"md5": "7192f9e27e8b84776d107f57cbe353d5",
"link": true,
"rounds": 1,
"enableXfa": true,
"type": "eq"
},
{ "id": "xfa_annual_expense_report",
"file": "pdfs/xfa_annual_expense_report.pdf",
"md5": "06866e7a6bbc0346789208ef5f6e885c",
Expand Down
49 changes: 47 additions & 2 deletions test/unit/xfa_tohtml_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ describe("XFAFactory", function () {
<medium stock="default" short="456pt" long="789pt"/>
<field y="1pt" w="11pt" h="22pt" x="2pt">
<ui>
<textEdit/>
<textEdit multiLine="0"/>
</ui>
<value>
<text maxChars="123"/>
Expand All @@ -160,9 +160,54 @@ describe("XFAFactory", function () {
expect(factory.numberPages).toEqual(1);

const pages = factory.getPages();
const field = searchHtmlNode(pages, "name", "textarea");
const field = searchHtmlNode(pages, "name", "input");

expect(field.attributes.maxLength).toEqual(123);
});

it("should have an input or textarea", 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>
</field>
<field y="1pt" w="11pt" h="22pt" x="2pt">
<ui>
<textEdit multiLine="1"/>
</ui>
</field>
</pageArea>
</pageSet>
<subform name="first">
<draw><value><text>foo</text></value></draw>
</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 field1 = searchHtmlNode(pages, "name", "input");
expect(field1).not.toEqual(null);

const field2 = searchHtmlNode(pages, "name", "textarea");
expect(field2).not.toEqual(null);
});
});
});

0 comments on commit 335d4cb

Please sign in to comment.