DeuxHuitHuit / quicksearch

A jQuery plugin for searching through DOM Elements quickly
https://www.npmjs.org/package/jquery.quicksearch
Other
135 stars 35 forks source link

Children elements being hidden too #1

Closed agentphoenix closed 10 years ago

agentphoenix commented 10 years ago
<div id="formsSearch">
     <div class="col-lg-6">
          <div class="thumbnail">
               <div class="btn-group"></div>
               <h4>Text</h4>
          </div>
     </div>
     ...
</div>
$('#searchForms').quicksearch('#formsSearch div', {
    hide: function()
    {
        $(this).addClass('hidden');
    },
    show: function()
    {
        $(this).removeClass('hidden');
        $(this).find('.btn-group').removeClass('hidden');
    }
});

I'm having an issue with the above markup where QuickSearch does exactly what it's supposed to do except that it hides all children elements as well. So when the search is finished running, it shows my h4 but the .btn-group is hidden and can't be shown. Am I doing something wrong with this? Let me know if you need anything else from me. Any help would be appreciated!

nitriques commented 10 years ago

The first selector you must used is target to the input tag.

Also, you first use #searchForms id and then #formsSearch is that alright ?

It should look more to this

$('#searchForms input[name="q"]').quicksearch('#searchForms div', { ... }
agentphoenix commented 10 years ago

The searchForms is actually the input field and formsSearch is the containing div. Everything is filtering like it should but the resulting HTML has the btn-group hidden (likely because the plugin recursively hides everything instead of just the containing element). Was just curious if you knew how to massage this so those children elements aren't hidden like that.

On Tuesday, November 5, 2013, Nicolas Brassard wrote:

The first selector you must used is target to the input tag.

Also, you first use #searchForms id and then #formsSearch is that alright ?

It should look more to this

$('#searchForms input[name="q"]').quicksearch('#searchForms div', { ... }

— Reply to this email directly or view it on GitHubhttps://github.com/DeuxHuitHuit/quicksearch/issues/1#issuecomment-27814569 .

nitriques commented 10 years ago

Hum ok. That's a problem sometimes with greedy selectors.

Just use this selector instead: '#searchForms>div'

This will make the plugin manipulate only direct descendants of the container div.

agentphoenix commented 10 years ago

That did the trick! I didn't realize changing the selector there would change the behavior of the plugin. Thanks for your help!

nitriques commented 10 years ago

Yeah that selector is the selector of the results item. Glad we could fix it.