Skip to content

Commit 36af189

Browse files
committed
Add an empty entry in combo list when nothing is selected (bug 1773680)
- it aims to fix https://bugzilla.mozilla.org/show_bug.cgi?id=1773680 - the empty is removed once something is selected.
1 parent 808a55e commit 36af189

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
lines changed

src/display/annotation_layer.js

+17
Original file line numberDiff line numberDiff line change
@@ -1461,6 +1461,8 @@ class ChoiceWidgetAnnotationElement extends WidgetAnnotationElement {
14611461
selectElement.setAttribute("id", id);
14621462
selectElement.tabIndex = DEFAULT_TAB_INDEX;
14631463

1464+
let hasAnEmptyEntry = true;
1465+
14641466
if (!this.data.combo) {
14651467
// List boxes have a size and (optionally) multiple selection.
14661468
selectElement.size = this.data.options.length;
@@ -1486,10 +1488,21 @@ class ChoiceWidgetAnnotationElement extends WidgetAnnotationElement {
14861488
}
14871489
if (storedData.value.includes(option.exportValue)) {
14881490
optionElement.setAttribute("selected", true);
1491+
hasAnEmptyEntry = false;
14891492
}
14901493
selectElement.appendChild(optionElement);
14911494
}
14921495

1496+
if (hasAnEmptyEntry && this.data.combo && this.data.options) {
1497+
const noneOptionElement = document.createElement("option");
1498+
noneOptionElement.value = " ";
1499+
noneOptionElement.setAttribute("hidden", true);
1500+
selectElement.insertBefore(noneOptionElement, selectElement.firstChild);
1501+
noneOptionElement.setAttribute("selected", true);
1502+
} else {
1503+
hasAnEmptyEntry = false;
1504+
}
1505+
14931506
const getValue = (event, isExport) => {
14941507
const name = isExport ? "value" : "textContent";
14951508
const options = event.target.options;
@@ -1602,6 +1615,10 @@ class ChoiceWidgetAnnotationElement extends WidgetAnnotationElement {
16021615
});
16031616

16041617
selectElement.addEventListener("input", event => {
1618+
if (hasAnEmptyEntry) {
1619+
selectElement.firstChild.remove();
1620+
hasAnEmptyEntry = false;
1621+
}
16051622
const exportValue = getValue(event, /* isExport */ true);
16061623
const value = getValue(event, /* isExport */ false);
16071624
storage.setValue(id, { value: exportValue });

test/pdfs/bug1773680.pdf.link

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
https://bugzilla.mozilla.org/attachment.cgi?id=9280675
2+

test/test_manifest.json

+8
Original file line numberDiff line numberDiff line change
@@ -6567,5 +6567,13 @@
65676567
"rounds": 1,
65686568
"type": "eq",
65696569
"annotations": true
6570+
},
6571+
{ "id": "bug1773680.pdf",
6572+
"file": "pdfs/bug1773680.pdf",
6573+
"md5": "6099fc695fe018ce444752929d86f9c8",
6574+
"rounds": 1,
6575+
"link": true,
6576+
"type": "eq",
6577+
"annotations": true
65706578
}
65716579
]

0 commit comments

Comments
 (0)