Use the export value instead of the display value for choice widget option selection

The export value is used when the document is saved, so it should also
be used when the document is opened to determine which choice widget
option is selected. The display value is, as the name implies, only to
be used for viewer display purposes and not for other logic.

This makes sure that in the document from #12233 the "Favourite colour"
choice widget is correctly initialized with "Red" instead of "Black"
because the field value is equal to the export value (always the case),
but not the display value (not always the case). Moreover, saving now
also correctly uses the export value and not the display value.
This commit is contained in:
Tim van der Meij 2020-08-22 13:57:12 +02:00
parent 37c5660394
commit 5fed7112a2
No known key found for this signature in database
GPG Key ID: 8C3FD2925A5F2762

View File

@ -682,16 +682,16 @@ class ChoiceWidgetAnnotationElement extends WidgetAnnotationElement {
const optionElement = document.createElement("option");
optionElement.textContent = option.displayValue;
optionElement.value = option.exportValue;
if (this.data.fieldValue.includes(option.displayValue)) {
if (this.data.fieldValue.includes(option.exportValue)) {
optionElement.setAttribute("selected", true);
storage.setValue(id, option.displayValue);
storage.setValue(id, option.exportValue);
}
selectElement.appendChild(optionElement);
}
selectElement.addEventListener("input", function (event) {
const options = event.target.options;
const value = options[options.selectedIndex].text;
const value = options[options.selectedIndex].value;
storage.setValue(id, value);
});