Skip to content

Commit

Permalink
XFA - Choice list has no selected value by default
Browse files Browse the repository at this point in the history
  • Loading branch information
calixteman committed Jun 28, 2021
1 parent 3f02a46 commit 1de133a
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/core/xfa/template.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -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 = {
Expand Down

0 comments on commit 1de133a

Please sign in to comment.