Skip to content

Commit

Permalink
[bugfix] when filtering dropdown items, in case whitelist items do no…
Browse files Browse the repository at this point in the history
…t contain any of the custom "mapValueTo" array strings, then use `value` instead
  • Loading branch information
yairEO committed Feb 13, 2021
1 parent 153996e commit cd87f4d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
9 changes: 7 additions & 2 deletions dist/tagify.min.js
Expand Up @@ -731,8 +731,13 @@
value: whitelist[i]
}; //normalize value as an Object

var itemWithoutSearchKeys = !Object.keys(whitelistItem).some(function (k) {
return searchKeys.includes(k);
}),
_searchKeys = itemWithoutSearchKeys ? ["value"] : searchKeys;

if (_sd.fuzzySearch && !options.exact) {
searchBy = searchKeys.reduce(function (values, k) {
searchBy = _searchKeys.reduce(function (values, k) {
return values + " " + (whitelistItem[k] || "");
}, "").toLowerCase();

Expand All @@ -743,7 +748,7 @@

valueIsInWhitelist = stringHasAll(searchBy, niddle);
} else {
valueIsInWhitelist = searchKeys.some(function (k) {
valueIsInWhitelist = _searchKeys.some(function (k) {
var v = '' + (whitelistItem[k] || ''); // if key exists, cast to type String

if (_sd.accentedSearch) {
Expand Down
7 changes: 5 additions & 2 deletions src/parts/dropdown.js
Expand Up @@ -546,8 +546,11 @@ export default {
for( ; i < whitelist.length; i++ ){
whitelistItem = whitelist[i] instanceof Object ? whitelist[i] : { value:whitelist[i] } //normalize value as an Object

let itemWithoutSearchKeys = !Object.keys(whitelistItem).some(k => searchKeys.includes(k) ),
_searchKeys = itemWithoutSearchKeys ? ["value"] : searchKeys

if( _sd.fuzzySearch && !options.exact ){
searchBy = searchKeys.reduce((values, k) => values + " " + (whitelistItem[k]||""), "").toLowerCase()
searchBy = _searchKeys.reduce((values, k) => values + " " + (whitelistItem[k]||""), "").toLowerCase()

if( _sd.accentedSearch ){
searchBy = unaccent(searchBy)
Expand All @@ -558,7 +561,7 @@ export default {
}

else {
valueIsInWhitelist = searchKeys.some(k => {
valueIsInWhitelist = _searchKeys.some(k => {
var v = '' + (whitelistItem[k] || '') // if key exists, cast to type String

if( _sd.accentedSearch ){
Expand Down

0 comments on commit cd87f4d

Please sign in to comment.