I did a search from a tutorial that can filter in any order of words.
My HTML Code
<input type="text" class="search-box">
<ul>
@for (int i = 0; i < Movies.Count; i++)
{
var movieTitle = Movies[i].Title;
var movieAuthor = Movies[i].Author;
<li class="item-list">@movieTitle</li>
}
</ul>
My Script
let inputElem = document.querySelector(".search-box");
inputElem.addEventListener("input", handleInput, false);
function handleInput() {
let inputElemValue = inputElem.value.toLowerCase();
let inputWordsArray = inputElemValue.split(" ");
let liHTMLCollection = document.getElementsByClassName("item-list");
Array.from(liHTMLCollection).forEach((li) => {
let innerTextLowerCase = li.innerHTML.toLowerCase();
let matching = true;
inputWordsArray.forEach((word) => {
let regex = new RegExp("\\b" + word);
if (regex.exec(innerTextLowerCase)) {
//if true - display
} else {
//if false hide
matching = false;
}
});
if (matching) {
li.style.display = "block";
} else {
li.style.display = "none";
}
});
}
What I want is to concatenate movieTitle and movieAuthor but I want movieAuthor to be hidden in front-end but can be searchable and will appear the movieTitle.
Thanks for answer