Home › Forums › Product Support Forums › Ajax Search Pro for WordPress Support › Filter Option for Unchecked Child Category by default on Selection Parent
This topic contains 14 replies, has 2 voices, and was last updated by theonlyit59 2 years ago.
- AuthorPosts
- February 28, 2021 at 2:58 pm #31843
Hi,
We are looking for option if we click parent category in filter, all child categories should be unchecked by default? How do we achieve this? Please see attachment for reference.Thank you
Regards,
Shayan AhmedAttachments:
You must be logged in to view attached files.March 1, 2021 at 2:59 pm #31858Hi,
Do you mean like only opening the sub-categories, but not checking them?
I’m afraid there is no option to do that unfortunately, but it might be possible via a custom code though.Try adding this custom code to the functions.php in your theme/child theme directory. Before editing, please make sure to have a full site back-up just in case!
add_action('wp_footer', 'asp_api_sample_code'); function asp_api_sample_code() { ?> <script> jQuery(function ($) { var settingsCheckboxToggle = function ($node) { var $parent = $node; var $checkbox = $node.find('input[type="checkbox"]'); var lvl = parseInt($node.data("lvl")) + 1; var i = 0; while (true) { $parent = $parent.next(); if ($parent.length > 0 && typeof $parent.data("lvl") != "undefined" && parseInt($parent.data("lvl")) >= lvl ) { if ($checkbox.prop("checked")) { $parent.removeClass("hiddend"); } else { $parent.addClass("hiddend"); } } else break; i++; if (i > 400) break; // safety first } } $('.asp_option_cat input[type="checkbox"]').off('asp_chbx_change'); $('.asp_option_cat input[type="checkbox"]').on('asp_chbx_change', function (e) { settingsCheckboxToggle($(this).closest('.asp_option_cat')); var id = $(this).closest('.asp_w').data('id'); var instance = $(this).closest('.asp_w').data('instance'); ASP.api(id, instance, 'searchFor'); }); }); </script> <?php }
With this the checkbox states should stay the same as they are initially. If they are set to unchecked by default, then they should stay unchecked after clicking on the parent.
Best,
Ernest Marcinko
If you like my products, don't forget to rate them on codecanyon :)
March 1, 2021 at 6:28 pm #31872Hi,
I have tried your code but nothing happens, By default, all the parent category checkboxes are unchecked. When I click one of the parent category checkboxes, all of the related child category checkboxes are shown but all of them are checked which I don’t want. After adding the above code this is the output I’m getting. Please see the attachment for reference.
Thank you
Regards,
Shayan AhmedAttachments:
You must be logged in to view attached files.March 2, 2021 at 11:19 am #31886It is probably not possible then. If you want, you can leave a link where I could check this out, but blindly I probably can not suggest anything else.
Best,
Ernest Marcinko
If you like my products, don't forget to rate them on codecanyon :)
March 2, 2021 at 12:26 pm #31890You cannot access this content.March 2, 2021 at 1:45 pm #31898I think the code is executed too soon. Try this variation instead:
add_action('wp_footer', 'asp_api_sample_code', 9999999999); function asp_api_sample_code() { ?> <script> jQuery(function ($) { var settingsCheckboxToggle = function ($node) { var $parent = $node; var $checkbox = $node.find('input[type="checkbox"]'); var lvl = parseInt($node.data("lvl")) + 1; var i = 0; while (true) { $parent = $parent.next(); if ($parent.length > 0 && typeof $parent.data("lvl") != "undefined" && parseInt($parent.data("lvl")) >= lvl ) { if ($checkbox.prop("checked")) { $parent.removeClass("hiddend"); } else { $parent.addClass("hiddend"); } } else break; i++; if (i > 400) break; // safety first } } setTimeout(function(){ $('.asp_option_cat input[type="checkbox"]').off('asp_chbx_change'); $('.asp_option_cat input[type="checkbox"]').on('asp_chbx_change', function (e) { settingsCheckboxToggle($(this).closest('.asp_option_cat')); var id = $(this).closest('.asp_w').data('id'); var instance = $(this).closest('.asp_w').data('instance'); ASP.api(id, instance, 'searchFor'); }); }, 500); }); </script> <?php }
This should move the script to the bottom and should override the behavior.
Best,
Ernest Marcinko
If you like my products, don't forget to rate them on codecanyon :)
March 2, 2021 at 2:51 pm #31900You cannot access this content.March 2, 2021 at 4:11 pm #31907Hi,
If the items are actually assigned to the parent category as well, then try this changing option here: https://i.imgur.com/BHManGY.png
Best,
If they are not assigned to the parent category, then unfortunately that is not possible.
Ernest Marcinko
If you like my products, don't forget to rate them on codecanyon :)
March 3, 2021 at 8:54 am #31925You cannot access this content.March 3, 2021 at 9:11 am #31927You cannot access this content.March 3, 2021 at 3:57 pm #31953With that code the child category checkboxes does not get unchecked for sure. I have double checked.
Best,
For example after loading the page and and clicking “Server management”:
– Initially the “Backup restore” is unchecked: https://i.imgur.com/aWvBse6.png
– Then I click “Server management”, the “Backup restore” still unchecked: https://i.imgur.com/6g3O6wS.png
– Then I click “Server management” again, the “Backup restore” still unchecked: https://i.imgur.com/mgBX2An.png
Ernest Marcinko
If you like my products, don't forget to rate them on codecanyon :)
March 3, 2021 at 6:46 pm #31955Well brother,
I also tested these steps.
– Initially the “Backup restore” is unchecked.
– Then I click “Server management”, the “Backup restore” still unchecked.
– Then I click the “Backup restore” it changes to checked state.
– Then I click “Server management” again while keeping the “Backup Restore” as checked, the “Backup restore” remains checked which I don’t want. What I want is when the parent category gets unchecked all the child categories should be unchecked as well. I Hope you got my point.Thank you
Regards,
Shayan AhmedAttachments:
You must be logged in to view attached files.March 3, 2021 at 7:08 pm #31960Plus, when I check any child category while keeping the parent category as checked. Results are showing according to parent category which includes all the child categories. Child categories are not further getting filtered.
Thank you
Regards,
Shayan AhmedAttachments:
You must be logged in to view attached files.March 4, 2021 at 9:40 am #31978I’m afraid you may have to ask someone for customization for this specific case. The code I suggested is a good starting point, it prevents changing the checkbox statuses when the parent category is clicked – it only needs an addition to uncheck them when the parent is unchecked.
Best,
Unfortunately this level of customization is way beyond our support duties, I hope you understand that.
Ernest Marcinko
If you like my products, don't forget to rate them on codecanyon :)
March 4, 2021 at 10:01 am #31982Hmm…Thank you for all the support you have given.
Regards,
Shayan Ahmed - AuthorPosts
You must be logged in to reply to this topic.