From a51c4a3a0f9f63245c7defe5308c6a6be6869945 Mon Sep 17 00:00:00 2001 From: Calixte Denizet Date: Thu, 22 Jul 2021 19:34:19 +0200 Subject: [PATCH] XFA - A field without an ui must provide a default one (bug 1718245) --- src/core/xfa/template.js | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/src/core/xfa/template.js b/src/core/xfa/template.js index 0670377c1..3dbb9844e 100644 --- a/src/core/xfa/template.js +++ b/src/core/xfa/template.js @@ -2548,6 +2548,37 @@ class Field extends XFAObject { } [$toHTML](availableSpace) { + if (!this.ui) { + // It's allowed to not have an ui, specs say: + // If the UI element contains no children or is not present, + // the application chooses a default user interface for the + // container, based on the type of the container's content. + + this.ui = new Ui({}); + this.ui[$globalData] = this[$globalData]; + this[$appendChild](this.ui); + let node; + + // The items element can have 2 element max and + // according to the items specs it's likely a good + // way to guess the correct ui type. + switch (this.items.children.length) { + case 0: + node = new TextEdit({}); + this.ui.textEdit = node; + break; + case 1: + node = new CheckButton({}); + this.ui.checkButton = node; + break; + case 2: + node = new ChoiceList({}); + this.ui.choiceList = node; + break; + } + this.ui[$appendChild](node); + } + setTabIndex(this); if ( @@ -2689,7 +2720,7 @@ class Field extends XFAObject { const borderStyle = this.border ? this.border[$toStyle]() : null; const bbox = computeBbox(this, html, availableSpace); - const ui = this.ui ? this.ui[$toHTML]().html : null; + const ui = this.ui[$toHTML]().html; if (!ui) { Object.assign(style, borderStyle); return HTMLResult.success(createWrapper(this, html), bbox);