Added support for OR (~) and optional AND (+) operators for tag searches.

This commit is contained in:
Keith Carangelo 2021-09-08 15:26:58 -04:00
parent 6e0f92acb4
commit a7d43caccb
4 changed files with 119 additions and 21 deletions
assets/default/js

View file

@ -45,8 +45,18 @@ function refreshToken(basePath, callback) {
function createAwesompleteInstance(element, separator, tags = []) {
const awesome = new Awesomplete(Awesomplete.$(element));
// Tags are separated by separator
awesome.filter = (text, input) => Awesomplete.FILTER_CONTAINS(text, input.match(new RegExp(`[^${separator}]*$`))[0]);
// Tags are separated by separator. Ignore leading search flags
awesome.filter = (text, input) => {
let filter_func = Awesomplete.FILTER_CONTAINS;
let input_flagged = input.replace( /^[\-\~\+]/, '' );
if (input !== input_flagged) {
input = input_flagged;
filter_func = Awesomplete.FILTER_STARTSWITH;
}
return filter_func(text, input.match(new RegExp(`[^${separator}]*$`))[0]);
};
// Insert new selected tag in the input
awesome.replace = (text) => {
const before = awesome.input.value.match(new RegExp(`^.+${separator}+|`))[0];