From 5fed7112a28db7394df86997f923366168fed6b6 Mon Sep 17 00:00:00 2001 From: Tim van der Meij Date: Sat, 22 Aug 2020 13:57:12 +0200 Subject: [PATCH] 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. --- src/display/annotation_layer.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/display/annotation_layer.js b/src/display/annotation_layer.js index f1385f86d..c1c6b4207 100644 --- a/src/display/annotation_layer.js +++ b/src/display/annotation_layer.js @@ -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); });