From 1de133a7c90276e9489b2a7756bc7bbbd8fdaeb5 Mon Sep 17 00:00:00 2001 From: Calixte Denizet Date: Mon, 28 Jun 2021 22:10:26 +0200 Subject: [PATCH] XFA - Choice list has no selected value by default --- src/core/xfa/template.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/core/xfa/template.js b/src/core/xfa/template.js index 659dc31fc..18d47c19f 100644 --- a/src/core/xfa/template.js +++ b/src/core/xfa/template.js @@ -1046,6 +1046,7 @@ class ChoiceList extends XFAObject { const displayed = items.children[displayedIndex][$toHTML]().html; const values = items.children[saveIndex][$toHTML]().html; + let selected = false; const value = (field.value && field.value[$text]()) || ""; for (let i = 0, ii = displayed.length; i < ii; i++) { const option = { @@ -1056,10 +1057,21 @@ class ChoiceList extends XFAObject { value: displayed[i], }; if (values[i] === value) { - option.attributes.selected = true; + option.attributes.selected = selected = true; } children.push(option); } + + if (!selected) { + children.splice(0, 0, { + name: "option", + attributes: { + hidden: true, + selected: true, + }, + value: " ", + }); + } } const selectAttributes = {