Skip to content

Instantly share code, notes, and snippets.

@guiprav
Created October 16, 2017 18:14
Show Gist options
  • Save guiprav/0371047ee6dde42c213ad3076b20db68 to your computer and use it in GitHub Desktop.
Save guiprav/0371047ee6dde42c213ad3076b20db68 to your computer and use it in GitHub Desktop.
$.fn.checkboxChildrenSelect = function() {
var $outermost = $(this);
function update() {
$outermost.find('.checkbox_children_select.group-label').each(function() {
var $checkedLeaves = $(this)
.closest('ul')
.find(':not(.group-label):checked');
$(this).prop('checked', $checkedLeaves.length !== 0);
});
}
update();
$outermost.find('.checkbox_children_select').change(function(ev) {
if (!ev.originalEvent) {
return;
}
if ($(this).hasClass('group-label')) {
$(this)
.closest('li')
.find('ul')
.find('.checkbox_children_select')
.prop('checked', $(this).prop('checked'));
}
update();
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment