From a554125f3eb6588d6019bd090c7db7fb04c9aba0 Mon Sep 17 00:00:00 2001 From: Evgeny Zinoviev Date: Tue, 21 Sep 2021 23:23:55 +0300 Subject: added showValueBeforeLabel option --- README.md | 3 +++ autocomplete.js | 7 ++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index b394308..28eb574 100644 --- a/README.md +++ b/README.md @@ -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(``); -- cgit v1.2.3