Fixed search method

This commit is contained in:
Макс Овсяников 2022-11-15 17:42:10 +03:00
parent fc67642d10
commit c25d983a02
2 changed files with 8 additions and 3 deletions

View File

@ -3,7 +3,7 @@
"version": "0.0.1", "version": "0.0.1",
"description": "", "description": "",
"scripts": { "scripts": {
"start": "parcel ./src/index.html -p 4500 --open ", "start": "parcel src/index.html -p 4500 --open ",
"build": "parcel build ./src/index.html --public-url /cg-select/", "build": "parcel build ./src/index.html --public-url /cg-select/",
"deploy": "gh-pages -d dist", "deploy": "gh-pages -d dist",
"predeploy": "npm run build" "predeploy": "npm run build"

View File

@ -758,16 +758,21 @@ export class DropDown {
input.oninput = function () { input.oninput = function () {
let val = this.value.trim(); let val = this.value.trim();
let anyMatch = false;
if (val != '') { if (val != '') {
searchSelect.forEach((elem) => { searchSelect.forEach((elem) => {
let isMatching = new RegExp(val, 'gi').test(elem.textContent);
anyMatch = anyMatch || isMatching;
if (elem.innerText.search(val) == -1) { if (elem.innerText.search(val) == -1) {
elem.classList.add('displayHide'); elem.classList.add('displayHide');
result.classList.remove('displayHide');
} else { } else {
elem.classList.remove('displayHide'); elem.classList.remove('displayHide');
} }
}); });
result.classList.toggle('displayHide', anyMatch);
} else { } else {
searchSelect.forEach((elem) => { searchSelect.forEach((elem) => {
elem.classList.remove('displayHide'); elem.classList.remove('displayHide');