diff --git a/src/display/annotation_layer.js b/src/display/annotation_layer.js index a712781874f369..2a03b3d33f0dfb 100644 --- a/src/display/annotation_layer.js +++ b/src/display/annotation_layer.js @@ -1461,6 +1461,8 @@ class ChoiceWidgetAnnotationElement extends WidgetAnnotationElement { selectElement.setAttribute("id", id); selectElement.tabIndex = DEFAULT_TAB_INDEX; + let hasAnEmptyEntry = true; + if (!this.data.combo) { // List boxes have a size and (optionally) multiple selection. selectElement.size = this.data.options.length; @@ -1486,10 +1488,27 @@ class ChoiceWidgetAnnotationElement extends WidgetAnnotationElement { } if (storedData.value.includes(option.exportValue)) { optionElement.setAttribute("selected", true); + hasAnEmptyEntry = false; } selectElement.appendChild(optionElement); } + let removeEmptyEntry = null; + if (hasAnEmptyEntry && this.data.combo && this.data.options.length > 0) { + const noneOptionElement = document.createElement("option"); + noneOptionElement.value = " "; + noneOptionElement.setAttribute("hidden", true); + noneOptionElement.setAttribute("selected", true); + selectElement.insertBefore(noneOptionElement, selectElement.firstChild); + + removeEmptyEntry = () => { + noneOptionElement.remove(); + selectElement.removeEventListener("input", removeEmptyEntry); + removeEmptyEntry = null; + }; + selectElement.addEventListener("input", removeEmptyEntry); + } + const getValue = (event, isExport) => { const name = isExport ? "value" : "textContent"; const options = event.target.options; @@ -1514,6 +1533,7 @@ class ChoiceWidgetAnnotationElement extends WidgetAnnotationElement { selectElement.addEventListener("updatefromsandbox", jsEvent => { const actions = { value(event) { + removeEmptyEntry?.(); const value = event.detail.value; const values = new Set(Array.isArray(value) ? value : [value]); for (const option of selectElement.options) { diff --git a/test/pdfs/bug1773680.pdf.link b/test/pdfs/bug1773680.pdf.link new file mode 100644 index 00000000000000..a66a4ab1acc6bb --- /dev/null +++ b/test/pdfs/bug1773680.pdf.link @@ -0,0 +1,2 @@ +https://bugzilla.mozilla.org/attachment.cgi?id=9280675 + diff --git a/test/test_manifest.json b/test/test_manifest.json index 39875d3a422b90..e78c2aa6e4b07f 100644 --- a/test/test_manifest.json +++ b/test/test_manifest.json @@ -6567,5 +6567,13 @@ "rounds": 1, "type": "eq", "annotations": true + }, + { "id": "bug1773680.pdf", + "file": "pdfs/bug1773680.pdf", + "md5": "6099fc695fe018ce444752929d86f9c8", + "rounds": 1, + "link": true, + "type": "eq", + "annotations": true } ]