From fb3e16cd7406249f5fc07e63e952e6037157ebee Mon Sep 17 00:00:00 2001 From: josedetorre <44461530+josedetorre@users.noreply.github.com> Date: Thu, 25 Oct 2018 12:47:15 +0200 Subject: [PATCH 1/4] #20181025UC - FORCE VALUES Hi there, I've developed a feature to let some values in the list to be allways selected (forced) In a list of Countries I needed to offer the user the "None of them" option ("Spain", "France", "UK", "Italy", "Other") so when she enters FR, the list returns "France", "Other", to let her choose default values. So, I 'm trying to set up a fork that needs three files and I am an absolutely NOOB at GitHub but I found this interesting and I liked to share. I've I upload wrong, please sorry for the inconvenience. --- src/proccessData.js | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/proccessData.js b/src/proccessData.js index b227fc5..12d9add 100644 --- a/src/proccessData.js +++ b/src/proccessData.js @@ -24,20 +24,23 @@ var EasyAutocomplete = (function(scope) { function findMatch(list, phrase) { - var preparedList = [], - value = ""; + var preparedList = [], + value = "", + force = false; if (config.get("list").match.enabled) { - for(var i = 0, length = list.length; i < length; i += 1) { + for (var i = 0, length = list.length; i < length; i += 1) { - value = config.get("getValue")(list[i]); - - if (match(value, phrase)) { - preparedList.push(list[i]); - } - - } + value = config.get("getValue")(list[i]); + force = list[i].force; + + if (match(value, phrase)) { + preparedList.push(list[i]); + } else if ((force != undefined) && (force == true)) { + preparedList.push(list[i]); + } + } } else { preparedList = list; @@ -92,4 +95,3 @@ var EasyAutocomplete = (function(scope) { })(EasyAutocomplete || {}); - From f269c4db5448663e45d74eb3cf585488a6ef07cf Mon Sep 17 00:00:00 2001 From: josedetorre <44461530+josedetorre@users.noreply.github.com> Date: Thu, 25 Oct 2018 12:49:04 +0200 Subject: [PATCH 2/4] #20181025UC - FORCE VALUES - CORE SEE #20181025UC - FORCE VALUES --- src/core.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/core.js b/src/core.js index 4203dfa..ab4d227 100644 --- a/src/core.js +++ b/src/core.js @@ -268,9 +268,17 @@ var EasyAutocomplete = (function(scope) { $listContainer.append("
" + listBuilders[builderIndex].header + "
"); } - for(var i = 0, listDataLength = listData.length; i < listDataLength && counter < listBuilders[builderIndex].maxListSize; i += 1) { - $item = $("
  • "); + for (var i = 0, listDataLength = listData.length; i < listDataLength && counter < listBuilders[builderIndex].maxListSize; i += 1) { + + // adding a css class to li to let the front-end show it differently + // example: .eac-item-forced .eac-item { color: #888; } + if ((listData[i].force != undefined) && (listData[i].force == true)) { + $item = $("
  • "); + } + else { + $item = $("
  • "); + } (function() { var j = i, From cd621c12d77f89abaf6f92f3c43fd65919c9f70c Mon Sep 17 00:00:00 2001 From: josedetorre <44461530+josedetorre@users.noreply.github.com> Date: Thu, 25 Oct 2018 12:50:31 +0200 Subject: [PATCH 3/4] #20181025UC - FORCE VALUES - CONFIGURATION SEE #20181025UC - FORCE VALUES --- src/configuration.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/configuration.js b/src/configuration.js index aa734d2..ef45b64 100644 --- a/src/configuration.js +++ b/src/configuration.js @@ -30,7 +30,15 @@ var EasyAutocomplete = (function(scope){ list: { sort: { enabled: false, - method: function(a, b) { + method: function (a, b) { + + fa = a.force; + fb = b.force; + + // if one of them is forced, promote the other (real matches go first) + if (fa && !fb) return 1; + if (fb && !fa) return -1; + a = defaults.getValue(a); b = defaults.getValue(b); @@ -361,4 +369,3 @@ var EasyAutocomplete = (function(scope){ return scope; })(EasyAutocomplete || {}); - From c903d9a5763878df1596feb5ab6f44c8de802db2 Mon Sep 17 00:00:00 2001 From: JOSE MANUEL DIAZ PEREZ <44461530+josedetorre@users.noreply.github.com> Date: Thu, 25 Oct 2018 13:39:00 +0200 Subject: [PATCH 4/4] Add title attribute I had a list with ellipsis text so I added title to drop-down list elements for the items reduced by ellipsis. --- src/core.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/core.js b/src/core.js index ab4d227..a6d344b 100644 --- a/src/core.js +++ b/src/core.js @@ -306,6 +306,7 @@ var EasyAutocomplete = (function(scope) { .mouseout(function() { config.get("list").onMouseOutEvent(); }) + .attr("title", elementsValue) .html(template.build(highlight(elementsValue, phrase), listData[j])); })();