rsanchez / dynamo

Makes Dynamic Parameters behave more like the Search module.
http://devot-ee.com/add-ons/dynamo/
10 stars 2 forks source link

Keeping checkboxes :checked #25

Closed jnsandrew closed 11 years ago

jnsandrew commented 11 years ago

Hi,

I'm having slight trouble getting my checkboxes to stay checked after submitting my form:

{exp:dynamo:form return="/{segment_1}" search_id="{segment_2}" dynamic_parameters="search:opp_tags"}
        <label>
            <input type="checkbox" name="search:opp_tags[]" value="course" {if search:opp_tags == "course"}checked="checked" {/if} />Course
        </label>

        <label>
            <input type="checkbox" name="search:opp_tags[]" value="exhibition" {if search:opp_tags == "exhibition"}checked="checked" {/if} />Exhibition
        </label>
{search:opp_tags}

The problem is with the IF statement. Using the code above, if I only check one box, it stays checked, but if I tick multiple, nothing stays checked.

I've also tried adding {if search:opp_tags[] == "exhibition} for example, including the [], that doesn't check anything - if i choose one or multiple checkboxes.

rsanchez commented 11 years ago

Can you try this:

{if {selected:search:opp_tags="course"}}{/if}
jnsandrew commented 11 years ago

Nope, if I copy and paste what you typed i get:

Parse error: parse error in /Users/andrewjones/Sites/website/ee-admin/expressionengine/libraries/Functions.php(679) : eval()'d code on line 88

If I add quotes like this:

{if "{selected:search:opp_tags="course"}" }   {/if}

I get:

A PHP Error was encountered
Severity: User Warning
Message: Invalid EE Conditional Variable: {if "{selected:search:opp_tags="course"}
Filename: libraries/Functions.php
Line Number: 2749

Just the tag on its own has no errors, just shows the tag on the page (so it doesn't recognise it)

{selected:search:opp_tags}
rsanchez commented 11 years ago

I was afraid that might happen. You'll need to grab this version (https://github.com/rsanchez/dynamo/tree/develop) and then do this:

        <label>
            <input type="checkbox" name="search:opp_tags[]" value="course" {if {exp:dynamo:selected value="course" in="{search:opp_tags}"}}checked="checked" {/if} />Course
        </label>
jnsandrew commented 11 years ago

Thanks Rob, I'll try this when I'm back at work on Monday. I'm already on the develop branch.

jnsandrew commented 11 years ago

Awesome, that solves the problem! Thanks.