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

Support archive

Maintain checkbox checked state on search results

Philip 16 May 2012 01:33 question, complete

I have a search form where I am populating a group of checkboxes from a channel. The search form submits to itself and I'd like to maintain the checked state of the checkboxes if possible so it's easily visible what was searched.

Code for the checkboxes is:

{exp:channel:entries dynamic="no" channel="tutor_subjects"}

 {title}

{/exp:channel:entries}

Replies

  1. Philip 16 May 2012 03:58

    just noticed that stripped out the HTML...

     
    <label class="form_label_check" for="subject{entry_id}">
    <input type="checkbox" id="subject{entry_id}" name="search:member_subjects[]" value="{title}" />&nbsp;{title}</label>

  2. Low 16 May 2012 08:19

    Hi Philip,

    First, make sure you feed the existing query to the low_search:form tag using the query="" parameter.

    Then, you could use this conditional:

    {if title IN ({low_search_search:member_subjects})} checked="checked"{/if}

  3. Low 16 May 2012 08:21

    See also the docs on the special form tag conditional and the advanced example below it.

  4. Philip 16 May 2012 12:16

    Thanks for that. Exactly what I needed. All working to plan!

  5. Stephen 25 Jun 2012 23:04

    Hi Low,

    I've got a similar query, but for a checkbox that comes from a Yes/No P&T Switch field. I've looked at your example above and the docs but can't figure this out. Here's what I'm trying:

    <input type="checkbox" name="search:cf_directory_family_friendly" value="Yes"{if Yes IN ({low_search_search:cf_directory_family_friendly})} checked="checked"{/if} />

    Any ideas where I'm going wrong with this?

    Thanks,

    Stephen

  6. Low 26 Jun 2012 08:19

    Hi Stephen,

    Since that variable isn't a multiple valued one, you should be able to do it like this:

    {if low_search_search:cf_directory_family_friendly == 'Yes'} ... {/if}


    The IN () syntax is especially useful for multiple valued fields, like the one in the original question.

  7. Stephen 26 Jun 2012 13:25

    Hi Low,

    Thanks for this - that worked great! :)

    The IN () syntax is a bit foreign to me as I'm not that familiar with SQL type queries, hence why I misunderstood its use without an identical example to copy from.

    I've got a P&T Dropdown field in my search form, and I've just added conditionals to detect the selected state of these. It works fine, but it felt like I was adding lots of conditionals. From a best practice point of view, I wondered if you'd recommend doing it in a better way, or does this look fine to you?

    Here's what I've done: http://pastie.org/private/sgaq6gh4q8w...

    Thanks,

    Stephen

  8. Low 27 Jun 2012 07:55

    That should be okay, Stephen. You might also want to take a look at Low Options, which might make things simpler: http://github.com/lodewijk/low_options

  9. Stephen 27 Jun 2012 11:44

    Thanks for this Low, and I'll be sire to check out Low Options.

    Thanks,

    Stephen