From 8a1ce1da15fdbae99b24700b06f2008c7a657603 Mon Sep 17 00:00:00 2001 From: ArthurHoaro Date: Thu, 5 Nov 2020 19:08:38 +0100 Subject: [PATCH 1/1] ESLint --- assets/default/js/base.js | 3 ++- assets/vintage/js/base.js | 10 ++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/assets/default/js/base.js b/assets/default/js/base.js index 37069d69..dd532bb7 100644 --- a/assets/default/js/base.js +++ b/assets/default/js/base.js @@ -55,7 +55,8 @@ function createAwesompleteInstance(element, separator, tags = []) { // Highlight found items awesome.item = (text, input) => Awesomplete.ITEM(text, input.match(new RegExp(`[^${separator}]*$`))[0]); // 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; awesome.data = (item, input) => { while ((match = reg.exec(input))) { diff --git a/assets/vintage/js/base.js b/assets/vintage/js/base.js index 15b664ce..55f1c37d 100644 --- a/assets/vintage/js/base.js +++ b/assets/vintage/js/base.js @@ -4,7 +4,7 @@ import 'awesomplete/awesomplete.css'; (() => { const autocompleteFields = document.querySelectorAll('input[data-multiple]'); const tagsSeparatorElement = document.querySelector('input[name="tags_separator"]'); - const tagsSeparator = tagsSeparatorElement ? tagsSeparatorElement.value || " " : " "; + const tagsSeparator = tagsSeparatorElement ? tagsSeparatorElement.value || ' ' : ' '; [...autocompleteFields].forEach((autocompleteField) => { const awesome = new Awesomplete(Awesomplete.$(autocompleteField)); @@ -12,8 +12,8 @@ import 'awesomplete/awesomplete.css'; // Tags are separated by separator awesome.filter = (text, input) => Awesomplete.FILTER_CONTAINS( text, - input.match(new RegExp(`[^${tagsSeparator}]*$`))[0]) - ; + input.match(new RegExp(`[^${tagsSeparator}]*$`))[0], + ); // Insert new selected tag in the input awesome.replace = (text) => { const before = awesome.input.value.match(new RegExp(`^.+${tagsSeparator}+|`))[0]; @@ -21,8 +21,10 @@ import 'awesomplete/awesomplete.css'; }; // Highlight found items awesome.item = (text, input) => Awesomplete.ITEM(text, input.match(new RegExp(`[^${tagsSeparator}]*$`))[0]); + // 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; awesome.data = (item, input) => { while ((match = reg.exec(input))) { -- 2.41.0