diff options
author | Evgeny Zinoviev <me@ch1p.io> | 2021-09-21 23:23:55 +0300 |
---|---|---|
committer | Evgeny Zinoviev <me@ch1p.io> | 2021-09-21 23:23:55 +0300 |
commit | a554125f3eb6588d6019bd090c7db7fb04c9aba0 (patch) | |
tree | f968d915fd1470347de33cce455333389371a041 | |
parent | 603ddb9323a6a1cba6776a87d68c6788a308c7aa (diff) |
added showValueBeforeLabel option
-rw-r--r-- | README.md | 3 | ||||
-rw-r--r-- | autocomplete.js | 7 |
2 files changed, 9 insertions, 1 deletions
@@ -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. diff --git a/autocomplete.js b/autocomplete.js index 169d3ed..a8de5fe 100644 --- a/autocomplete.js +++ b/autocomplete.js @@ -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>`); |