Forums Forums Search & Filter Pro Select/deselect all children when selecting parent (hierarchical checkbox)

Viewing 2 posts - 1 through 2 (of 2 total)
  • Anonymous
    #51749

    Hi, I would like to be able to select and deselect all children if I select/deselect parent categories. I found this thread (https://support.searchandfilter.com/forums/topic/hierarchical-filters-select-all-children-when-selecting-parent/) and saw that a member created the following code:

    $(document).ready(function() {	
    
    	var form = $('form.searchandfilter');
    	
    	if(typeof form === 'undefined') return;
    	
    	if(form.data('auto-update') == 1) return;
    
        form.parent().on('click', function (evt){ // bind click outside form in order to work with ajax
    
        	// the clicked form item
        	var _item = $(evt.target).closest('li');
        	
        	// styling stuff
        	if(_item.hasClass('sf-level-0')){
    			_item.toggleClass('sf-option-active');
    		}
    
    		// check/uncheck item and all children as well
    		// chose checkbox as form field options in plugin ui.
    		var _checked = _item.find('.sf-input-checkbox').prop('checked') == true ? false : true;
    		_item.find('.sf-input-checkbox').prop('checked', _checked);
    
    		// uncheck parent when unchecking child
    		if(!_checked){
    			var _parent_li = _item.parent().closest('li');
    			_parent_li.removeClass('sf-option-active'); // styling stuff
    			_parent_li.find(' > .sf-input-checkbox').prop('checked', false);
    		}
    
    		form.submit();
    
        	evt.stopPropagation();
    	evt.preventDefault();
        });
    });

    They said it works so I would love to add this. However, I’m not sure exactly which php file to edit for this functionality. Any help would be appreciated.

    Thanks!

    Trevor
    #51795

    The code you show is jQuery, and would need to be loaded via whatever methods your theme (Enfold?) allows. You need to refer to the theme help to answer that.

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