Merge pull request #15020 from calixteman/1773680
Add an empty entry in combo list when nothing is selected (bug 1773680)
This commit is contained in:
commit
6e6d94ab8d
@ -1461,6 +1461,8 @@ class ChoiceWidgetAnnotationElement extends WidgetAnnotationElement {
|
|||||||
selectElement.setAttribute("id", id);
|
selectElement.setAttribute("id", id);
|
||||||
selectElement.tabIndex = DEFAULT_TAB_INDEX;
|
selectElement.tabIndex = DEFAULT_TAB_INDEX;
|
||||||
|
|
||||||
|
let addAnEmptyEntry = this.data.combo && this.data.options.length > 0;
|
||||||
|
|
||||||
if (!this.data.combo) {
|
if (!this.data.combo) {
|
||||||
// List boxes have a size and (optionally) multiple selection.
|
// List boxes have a size and (optionally) multiple selection.
|
||||||
selectElement.size = this.data.options.length;
|
selectElement.size = this.data.options.length;
|
||||||
@ -1486,10 +1488,27 @@ class ChoiceWidgetAnnotationElement extends WidgetAnnotationElement {
|
|||||||
}
|
}
|
||||||
if (storedData.value.includes(option.exportValue)) {
|
if (storedData.value.includes(option.exportValue)) {
|
||||||
optionElement.setAttribute("selected", true);
|
optionElement.setAttribute("selected", true);
|
||||||
|
addAnEmptyEntry = false;
|
||||||
}
|
}
|
||||||
selectElement.appendChild(optionElement);
|
selectElement.appendChild(optionElement);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let removeEmptyEntry = null;
|
||||||
|
if (addAnEmptyEntry) {
|
||||||
|
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 getValue = (event, isExport) => {
|
||||||
const name = isExport ? "value" : "textContent";
|
const name = isExport ? "value" : "textContent";
|
||||||
const options = event.target.options;
|
const options = event.target.options;
|
||||||
@ -1514,6 +1533,7 @@ class ChoiceWidgetAnnotationElement extends WidgetAnnotationElement {
|
|||||||
selectElement.addEventListener("updatefromsandbox", jsEvent => {
|
selectElement.addEventListener("updatefromsandbox", jsEvent => {
|
||||||
const actions = {
|
const actions = {
|
||||||
value(event) {
|
value(event) {
|
||||||
|
removeEmptyEntry?.();
|
||||||
const value = event.detail.value;
|
const value = event.detail.value;
|
||||||
const values = new Set(Array.isArray(value) ? value : [value]);
|
const values = new Set(Array.isArray(value) ? value : [value]);
|
||||||
for (const option of selectElement.options) {
|
for (const option of selectElement.options) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user