Skip to content

Instantly share code, notes, and snippets.

@daum
Created October 24, 2014 15:33
Show Gist options
  • Save daum/8cb21d956acc84761bd2 to your computer and use it in GitHub Desktop.
Save daum/8cb21d956acc84761bd2 to your computer and use it in GitHub Desktop.
{% block checkbox_hierarchy_widget %}
<ul class="listless spaced-listless" id="mainList">
{% for choiceOrOptionGroup,children in form.vars.choices %}
{% if children is iterable %}
<ul>
{% for child,choiceView in children %}
<li>
<label class="checkbox">
{{ form_widget(form.offsetGet(child)) }}
{{ form.offsetGet(child).vars.label }}
</label>
</li>
{% endfor %}
</ul>
{% else %}
{# If not first loop, close previous <li> #}
{% if not loop.first %}
</li>
{% endif %}
<li>
<label class="checkbox">
{{ form_widget(form.offsetGet(choiceOrOptionGroup)) }}
{{ form.offsetGet(choiceOrOptionGroup).vars.label }}
</label>
{% endif %}
{# Last of the loop, there will be an open <li>, close it. #}
{% if loop.last %}
</li>
{% endif %}
{% endfor %}
</ul>
<script type="text/javascript">
$("#mainList").children('li').find('input:first').on('change',function(e,isPageLoad){
var children = $(this).parents('li:first').find('ul').find('input');
if($(this).is(':checked'))
{
children.prop('disabled',false);
if(!isPageLoad)
children.prop('checked',true);
}
else
{
children.prop('disabled',true).prop('checked',false);
}
}).trigger('change',[true]);
</script>
{% endblock %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment