[Annotations] Add support for printing/saving choice list with multiple selections

- it aims to fix issue #12189.
This commit is contained in:
Calixte Denizet 2022-03-26 22:45:50 +01:00
parent 0dd6bc9a85
commit ad3fb71a02
7 changed files with 355 additions and 33 deletions

View file

@ -1336,16 +1336,8 @@ class ChoiceWidgetAnnotationElement extends WidgetAnnotationElement {
const storage = this.annotationStorage;
const id = this.data.id;
// For printing/saving we currently only support choice widgets with one
// option selection. Therefore, listboxes (#12189) and comboboxes (#12224)
// are not properly printed/saved yet, so we only store the first item in
// the field value array instead of the entire array. Once support for those
// two field types is implemented, we should use the same pattern as the
// other interactive widgets where the return value of `getValue`
// is used and the full array of field values is stored.
storage.getValue(id, {
value:
this.data.fieldValue.length > 0 ? this.data.fieldValue[0] : undefined,
const storedData = storage.getValue(id, {
value: this.data.fieldValue,
});
let { fontSize } = this.data.defaultAppearanceData;
@ -1386,7 +1378,7 @@ class ChoiceWidgetAnnotationElement extends WidgetAnnotationElement {
if (this.data.combo) {
optionElement.style.fontSize = fontSizeStyle;
}
if (this.data.fieldValue.includes(option.exportValue)) {
if (storedData.value.includes(option.exportValue)) {
optionElement.setAttribute("selected", true);
}
selectElement.appendChild(optionElement);
@ -1537,7 +1529,7 @@ class ChoiceWidgetAnnotationElement extends WidgetAnnotationElement {
);
} else {
selectElement.addEventListener("input", function (event) {
storage.setValue(id, { value: getValue(event) });
storage.setValue(id, { value: getValue(event, /* isExport */ true) });
});
}