All Low add-ons are now owned by EEHarbor. Read the blog post.

Support archive

low search: using checkboxes to filter by category groups

pirco 7 Nov 2013 05:15 question, complete

I'm using category groups to filter search results just like the documentation shows but want to use checkboxes instead of a select box. it's working but on the results page, the originally selected filters are not checked anymore (so when I checked on category X then the search results actually do filter by category X but the checkbox isn't marked).

is there something I need to change?

{exp:channel:categories channel="installations|lighting" style="linear" category_group="2"}
< input type="checkbox" name="category:style[]" value="{category_id}"
{if category_id IN ({low_search_category})} checked="checked"{/if} / > {category_name}
{/exp:channel:categories}

on topic: what's the difference between name="category:style[]" and name="category:style" ?

thanks

Replies

  1. Low 7 Nov 2013 07:09

    The variable name should match the input name (without square brackets), so use this conditional instead:

    {if category IN ({low_search_category:style})}checked="checked"{/if}


    The square brackets make the input return an array instead of a single value, so that's needed if you want to submit multiple values for a single parameter.

  2. pirco 7 Nov 2013 15:28

    makes perfect sense now :-)

    brilliant.

    thank you!

  3. Patricia Vaccaro-Coburn 19 Feb 2015 17:52

    Hi, I'm looking for a similar result but get an error when I add in the conditional:

    "You have an invalid conditional in your template. Please review your conditionals for an unclosed string, invalid operators, a missing }, or a missing {/if}.

    Parser State: Unexpected ‘IN’ (VARIABLE); expected RD in Snippet “sn-sidebar-projects” on line 10."

    Here's my code (hopefully..I'm forever forgetting how to properly include it):


    {exp:channel:categories category_group="8" id="filter"}
    <input type="checkbox" name="category:region[]" value="{category_id}" {if category IN ({low_search_category:region})} checked="checked"{/if}>
    <label for="category:region[]">{category_name}</label>
    {/exp:channel:categories}


    Any tips?

  4. Low 19 Feb 2015 17:55

    You're probably on EE2.9+, where IN conditionals break.

    See this: http://gotolow.com/blog/conditional-conundrums
    And this: http://gotolow.com/addons/low-search/docs/parameters#in-conditionals

  5. Patricia Vaccaro-Coburn 20 Feb 2015 20:19

    Thank you!

    For anyone reading who had this problem, the code that worked for me was:


    <input type="checkbox" name="category:region[]" value="{category_id}"{if low_search_category:region ~ '/(^|\|)'.category_id.'($|\|)/'}checked="checked"{/if}>