Home › Forums › Product Support Forums › Ajax Search Pro for WordPress Support › Filter Option for Unchecked Child Category by default on Selection Parent › Reply To: Filter Option for Unchecked Child Category by default on Selection Parent
March 2, 2021 at 1:45 pm
#31898
Keymaster
I 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.