Forums Forums Search & Filter Pro Uncheck children checkbox

Viewing 5 posts - 1 through 5 (of 5 total)
  • Anonymous
    #117626

    Hi,

    I was wondering if it’s possible to uncheck children if parent is unchecked.
    It would concern a hierarchical custom taxonomy filter.

    Parent x <- unchecking this would uncheck all children.
    – child
    – child x
    – child
    – child x

    If I try some jQuery* it only triggers on the first check but afterwards the jquery doesn’t trigger anymore.

    *Like this:
    https://stackoverflow.com/questions/16420999/jquery-checkbox-how-to-uncheck-child-and-subchild-when-parent-is-unchecked

    Thanks in advance!

    Trevor
    #117656

    Are you able to share the js that you used? Is it included inline on the page or in an external file?

    When pasting code here, use the snippet key ‘back ticks’ to enclose (before and after) code:

    snippet backticks

    Anonymous
    #120689

    Hi, sorry for the late reply (forgot to enable email notifications), but I figured it out;
    I was trying to ‘uncheck’ children checkboxes when parent is unchecked.

    
    jQuery(document).ready(function($) {
    	
    	$(document).on('click','.sf-level-0.sf-option-active .sf-label-checkbox:first', function() {
    		$(this).parent().children().find('.sf-input-checkbox:checked').click();
    	
    	});
    	$(document).on('click','.sf-level-1.sf-option-active .sf-label-checkbox:first', function() {
    		$(this).parent().children().find('.sf-input-checkbox:checked').click();
    	
    	});
    
    });
    
    Trevor
    #120698

    Wouldn’t it be better to use onchange, then check the value, then do the actions?

    Anonymous
    #120724

    Probably :-).

    Thanks I’ll try it.

Viewing 5 posts - 1 through 5 (of 5 total)