Forums › Forums › Search & Filter Pro › Hierarchical Filters: Select all children when selecting parent
Tagged: hierarchical
- This topic has 5 replies, 2 voices, and was last updated 8 years, 6 months ago by Anonymous.
Viewing 6 posts - 1 through 6 (of 6 total)
-
Anonymous(Private) May 24, 2016 at 1:22 pm #46485
Hello!
We have a site running with S&F and results are great!
We would like to reproduce the following behaviour with a hierarchical taxonomy field:
- Select also all children when selecting a parent
- Unselect parent when unselecting a child
Expected result after first click on parent category “PASTA”
Expected filters in url after first click: _sft_recipe_cat=pasta,pasta-rellena,pasta-larga,pasta-corta
Expected result after second click on child category “PASTA LARGA”
Expected filters in url after second click: _sft_recipe_cat=pasta-rellena,pasta-corta
Is this possible?
Anonymous(Private) May 25, 2016 at 12:38 pm #46643Thank you Trevor.
Here is the approach we came with$(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(); }); });
-
AuthorPosts
Viewing 6 posts - 1 through 6 (of 6 total)