Skip to content

Commit

Permalink
Fixed issue with suggestions on multiple terms
Browse files Browse the repository at this point in the history
  • Loading branch information
kcaran committed Sep 9, 2021
1 parent c6f27b1 commit d2019d3
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions assets/default/js/base.js
Expand Up @@ -48,18 +48,19 @@ function createAwesompleteInstance(element, separator, tags = []) {
// Tags are separated by separator. Ignore leading search flags
awesome.filter = (text, input) => {
let filterFunc = Awesomplete.FILTER_CONTAINS;
const inputFlagged = input.replace(/^[-~+]/, '');
if (input !== inputFlagged) {
input = inputFlagged;
let term = input.match(new RegExp(`[^${separator}]*$`))[0];
const termFlagged = term.replace(/^[-~+]/, '');
if (term !== termFlagged) {
term = termFlagged;
filterFunc = Awesomplete.FILTER_STARTSWITH;
}

return filterFunc(text, input.match(new RegExp(`[^${separator}]*$`))[0]);
return filterFunc(text, term);
};

// Insert new selected tag in the input
awesome.replace = (text) => {
const before = awesome.input.value.match(new RegExp(`^.+${separator}+|`))[0];
const before = awesome.input.value.match(new RegExp(`^(.+${separator}+)?[-~+]?|`))[0];
awesome.input.value = `${before}${text}${separator}`;
};
// Highlight found items
Expand Down

0 comments on commit d2019d3

Please sign in to comment.