This commit is contained in:
ArthurHoaro 2020-11-05 19:08:38 +01:00
parent df9aac5b64
commit 8a1ce1da15
2 changed files with 8 additions and 5 deletions

View file

@ -55,7 +55,8 @@ function createAwesompleteInstance(element, separator, tags = []) {
// Highlight found items // Highlight found items
awesome.item = (text, input) => Awesomplete.ITEM(text, input.match(new RegExp(`[^${separator}]*$`))[0]); awesome.item = (text, input) => Awesomplete.ITEM(text, input.match(new RegExp(`[^${separator}]*$`))[0]);
// Don't display already selected items // Don't display already selected items
const reg = new RegExp(`/(\w+)${separator}/g`); // WARNING: pseudo classes does not seem to work with string litterals...
const reg = new RegExp(`([^${separator}]+)${separator}`, 'g');
let match; let match;
awesome.data = (item, input) => { awesome.data = (item, input) => {
while ((match = reg.exec(input))) { while ((match = reg.exec(input))) {

View file

@ -4,7 +4,7 @@ import 'awesomplete/awesomplete.css';
(() => { (() => {
const autocompleteFields = document.querySelectorAll('input[data-multiple]'); const autocompleteFields = document.querySelectorAll('input[data-multiple]');
const tagsSeparatorElement = document.querySelector('input[name="tags_separator"]'); const tagsSeparatorElement = document.querySelector('input[name="tags_separator"]');
const tagsSeparator = tagsSeparatorElement ? tagsSeparatorElement.value || " " : " "; const tagsSeparator = tagsSeparatorElement ? tagsSeparatorElement.value || ' ' : ' ';
[...autocompleteFields].forEach((autocompleteField) => { [...autocompleteFields].forEach((autocompleteField) => {
const awesome = new Awesomplete(Awesomplete.$(autocompleteField)); const awesome = new Awesomplete(Awesomplete.$(autocompleteField));
@ -12,8 +12,8 @@ import 'awesomplete/awesomplete.css';
// Tags are separated by separator // Tags are separated by separator
awesome.filter = (text, input) => Awesomplete.FILTER_CONTAINS( awesome.filter = (text, input) => Awesomplete.FILTER_CONTAINS(
text, text,
input.match(new RegExp(`[^${tagsSeparator}]*$`))[0]) input.match(new RegExp(`[^${tagsSeparator}]*$`))[0],
; );
// Insert new selected tag in the input // Insert new selected tag in the input
awesome.replace = (text) => { awesome.replace = (text) => {
const before = awesome.input.value.match(new RegExp(`^.+${tagsSeparator}+|`))[0]; const before = awesome.input.value.match(new RegExp(`^.+${tagsSeparator}+|`))[0];
@ -21,8 +21,10 @@ import 'awesomplete/awesomplete.css';
}; };
// Highlight found items // Highlight found items
awesome.item = (text, input) => Awesomplete.ITEM(text, input.match(new RegExp(`[^${tagsSeparator}]*$`))[0]); awesome.item = (text, input) => Awesomplete.ITEM(text, input.match(new RegExp(`[^${tagsSeparator}]*$`))[0]);
// Don't display already selected items // Don't display already selected items
const reg = new RegExp(`/(\w+)${tagsSeparator}/g`); // WARNING: pseudo classes does not seem to work with string litterals...
const reg = new RegExp(`([^${tagsSeparator}]+)${tagsSeparator}`, 'g');
let match; let match;
awesome.data = (item, input) => { awesome.data = (item, input) => {
while ((match = reg.exec(input))) { while ((match = reg.exec(input))) {