matteodem / meteor-easy-search

Easy-to-use search for Meteor with Blaze Components
MIT License
438 stars 68 forks source link

How to set EasySearch.IfInputEmpty programmatically? #528

Closed krishaamer closed 7 years ago

krishaamer commented 7 years ago

Thank you for the awesome package!

I'm using the search input in the header of the site where it's always visible. While the user is searching I hide the content using {{#EasySearch.IfInputEmpty}} to highlight the search results (which otherwise would be lower on the page below the content).

screenshot 2016-09-01 14 22 18

screenshot 2016-09-01 14 20 53

Now when the user clicks on one of the results the input is still populated with the search string so the new page content remains hidden.

How would be the best way to set the search string empty? Just setting the input element to undefined using $ doesn't work as {{#EasySearch.IfInputEmpty}} still seems to think there's content in the search field so the content remains hidden.

So how can we reset the search input?

Any advice would be appreciated.

Thanks, -Kris https://yah.haam.co/

krishaamer commented 7 years ago

So if anyone has the same problem, what I ended up doing is faking the user with

    $("#search").val("");
    $('#search').focus();
    $('#search').keydown();
    $('#search').keypress();
    $('#search').keyup();
    $('#search').blur();

It works but is perhaps not the most elegant solution. So if you have something better, please do let me know below.

Cheers, -Kris

matteodem commented 7 years ago

Hi kris

I'm sorry for the late answer, but probably you want to use the component methods? http://matteodem.github.io/meteor-easy-search/docs/components/. There's a method called search, see the code for the input component https://github.com/matteodem/meteor-easy-search/blob/master/packages/easysearch:components/lib/input/input.js#L13.

matteodem commented 7 years ago

Let me know if that's not what you were looking for.

krishaamer commented 7 years ago

Yes, that solved it! Thank you so much!