How do I check if a checkbox is checked?

Thomas Watson's Avatar

Thomas Watson

18 Aug, 2010 12:58 PM via web

I have a custom checkbox field in my template containing two checkboxes.
How do I check which checkbox is checked in my template?

  1. Support Staff 2 Posted by Steve Smith on 18 Aug, 2010 02:44 PM

    Steve Smith's Avatar

    The easiest way is {% if item.data.checkbox_name != blank %}

  2. 3 Posted by Thomas Watson on 18 Aug, 2010 04:20 PM

    Thomas Watson's Avatar

    Don't I then only get the checkbox field "wrapper"?

    As far as I understand the system, a checkbox field is actually not a single checkbox but a group of checkboxes. The only identifier I give a checkbox is its label (the text shown to the right of the checkbox) - i.e. the text that is shown to the user

    In my case (see attached screenshot) I have a checkbox field with more than one checkbox and I want to verify if a specific one of them is checked.

  3. 4 Posted by Thomas Watson on 31 Aug, 2010 12:00 PM

    Thomas Watson's Avatar

    Anybody?

  4. 5 Posted by John Nunemaker on 02 Sep, 2010 02:11 AM

    John Nunemaker's Avatar

    Gotcha. Misunderstood the first time. Just did some small tests. It appears there isn't an easy way right now. I'm looking at adding something to help you out.

  5. 6 Posted by John Nunemaker on 02 Sep, 2010 03:09 AM

    John Nunemaker's Avatar

    Ok, I put together an include filter.

    http://docs.harmonyapp.com/harmony-templates/filters/array-filters/...

    The docs show how to use it in an if statement. Unfortunately, filters cannot be used in if statements so you have to assign the result to a variable and then use the variable in an if statement. If you follow the link above, the example should explain things.

    Hope this helps.

  6. John Nunemaker closed this discussion on 02 Sep, 2010 03:09 AM.

Comments are currently closed for this discussion. You can start a new one.

Recent Discussions

17 May, 2012 10:45 PM
20 Mar, 2012 05:05 PM
26 Apr, 2012 01:40 AM
07 Mar, 2012 04:42 PM