added showValueBeforeLabel option

This commit is contained in:
Evgeny Zinoviev 2021-09-21 23:23:55 +03:00
parent 603ddb9323
commit a554125f3e
2 changed files with 9 additions and 1 deletions

View File

@ -84,6 +84,9 @@ A callback that is fired every time an item is selected. It receives an object i
**showValue**:
If set to true, will display the value of the entry after the label in the dropdown list.
**showValueBeforeLabel**
If set to true and **`showValue`** also set to true, the value will be displayed before the label.
**treshold**:
The number of characters that need to be typed on the input in order to trigger the autocomplete. Default is 4.

View File

@ -6,6 +6,7 @@ const DEFAULTS = {
label: 'label',
value: 'value',
showValue: false,
showValueBeforeLabel: false,
};
class Autocomplete {
@ -77,7 +78,11 @@ class Autocomplete {
}
if (this.options.showValue) {
label += ` ${item.value}`;
if (this.options.showValueBeforeLabel) {
label = `${item.value} ${label}`;
} else {
label += ` ${item.value}`;
}
}
return ce(`<button type="button" class="dropdown-item" data-label="${item.label}" data-value="${item.value}">${label}</button>`);