Skip to content

Commit 072e0d4

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 072e0d4

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

src/display/annotation_layer.js

+20
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,27 @@ 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+
let removeEmptyEntry = null;
1497+
if (hasAnEmptyEntry && this.data.combo && this.data.options.length > 0) {
1498+
const noneOptionElement = document.createElement("option");
1499+
noneOptionElement.value = " ";
1500+
noneOptionElement.setAttribute("hidden", true);
1501+
noneOptionElement.setAttribute("selected", true);
1502+
selectElement.insertBefore(noneOptionElement, selectElement.firstChild);
1503+
1504+
removeEmptyEntry = () => {
1505+
noneOptionElement.remove();
1506+
selectElement.removeEventListener("input", removeEmptyEntry);
1507+
removeEmptyEntry = null;
1508+
};
1509+
selectElement.addEventListener("input", removeEmptyEntry);
1510+
}
1511+
14931512
const getValue = (event, isExport) => {
14941513
const name = isExport ? "value" : "textContent";
14951514
const options = event.target.options;
@@ -1514,6 +1533,7 @@ class ChoiceWidgetAnnotationElement extends WidgetAnnotationElement {
15141533
selectElement.addEventListener("updatefromsandbox", jsEvent => {
15151534
const actions = {
15161535
value(event) {
1536+
removeEmptyEntry?.();
15171537
const value = event.detail.value;
15181538
const values = new Set(Array.isArray(value) ? value : [value]);
15191539
for (const option of selectElement.options) {

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)