I'm using a library ListJs to perform fuzzy search and is working perfectly, but there is only one issue, I want the results only show when the user is searching and not showing all results how most of the examples of the documentation is showing.
I can't find any example for what I'm looking, is it possible ListJs have an option that makes results available only one search mode?
HTML:
<div id="sandbox">
<input class="form-control form-control-lg fuzzy-search" placeholder="Search" />
<ul class="list" id="list"></ul>
</div>
JS:
var options = {
valueNames: [
'productTitle',
'productBrand',
{ name: 'productImage', attr: 'src' }
],
item: '<li>
<img src="" class="img-fluid productImage" style="height: 100px;" alt="#" />
<h3 class="productTitle"></h3>
<p class="productBrand"></p>
</li>'
};
var userList = new List('sandbox', options);
$.getJSON( "data.json", function( data ) {
userList.add(data);
});
Ok so i am not sure i understood what you wanted but i will give it a go since you didn't get a single answer yet.
What i think you want : By default the list is hidden. When the user focus the search field, the list shows up. When focus is lost, the list is hidden again.
You can solve this problem with some js (you could use jquery for selectors and hide() show() methods) :
HTML :
JS :
Here is a link to a codepen, example based on another example of listjs website.
Hope this helps, Cheers !