Maintain checkbox checked state on search results
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
Philip 16 May 2012 03:58
just noticed that stripped out the HTML...
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:
Low 16 May 2012 08:21
See also the docs on the special form tag conditional and the advanced example below it.
Philip 16 May 2012 12:16
Thanks for that. Exactly what I needed. All working to plan!
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
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:
The IN () syntax is especially useful for multiple valued fields, like the one in the original question.
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
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
Stephen 27 Jun 2012 11:44
Thanks for this Low, and I'll be sire to check out Low Options.
Thanks,
Stephen