rsanchez / dynamo

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

Check selected categories #15

Closed katrinkerber closed 11 years ago

katrinkerber commented 11 years ago

I can't quite see how I can check selected categories once the form has been submitted.

My form code:

{exp:dynamo:form return="{homepage}/{segment_1}/filtered/" search_id="{segment_3}"}
  {exp:gwcode_categories cat_id="{segment_1_category_id}" output_depth="3" style="linear" entry_count="yes"}
      <label for="{cat_name}" class="checkboxlabel">
        <input type="checkbox" name="category[]" id="{cat_name}" value="{cat_id}" {if category == {cat_id}} selected="selected"{/if}>
        {cat_name} ({entry_count})
      </label>
    {if cat_count == results_total}
      <input type="submit" value="Apply filters" class="btn classy">
    {/if}
  {/exp:gwcode_categories}
{/exp:dynamo:form}

What do I need to put in the IF conditional to check the selected categories?

rsanchez commented 11 years ago

This is possible using the [develop]() branch.

{exp:dynamo:form return="{homepage}/{segment_1}/filtered/" search_id="{segment_3}" dynamic_parameters="category"}
  {exp:gwcode_categories cat_id="{segment_1_category_id}" output_depth="3" style="linear" entry_count="yes"}
      <label for="{cat_name}" class="checkboxlabel">
        <input type="checkbox" name="category[]" id="{cat_name}" value="{cat_id}" {if {exp:dynamo:selected value="{cat_id}" in="{category}"}} selected="selected"{/if}>
        {cat_name} ({entry_count})
      </label>
    {if cat_count == results_total}
      <input type="submit" value="Apply filters" class="btn classy">
    {/if}
  {/exp:gwcode_categories}
{/exp:dynamo:form}
katrinkerber commented 11 years ago

For some reason

{exp:dynamo:selected value="{cat_id}" in="{category}"}

always returns "0".

When I try:

{if "{cat_id}" == "{category}"} checked {/if}

then that works great if only one value has been selected. Of course, that doesn't work when two have been selected.

Any ideas?

rsanchez commented 11 years ago

Try adding parse="inward" to the gwcode_categories tag.

katrinkerber commented 11 years ago

That worked. Thank you very much.