I am using a plugin that only triggers on click of checkbox , I need All button checkbox to existing code. I have made it so that on click of ALL CHECKBOX I manually TRIGGER click selecting all checkbox and firing the existing jquery code The problem comes when user clicks on one of checkbox I want that option to be as selected option so if all checkbox are checked (including the All) and user clicks on 3rd checkbox it should automatically select 3rd checkbox trigger click on all others (making them unchecked) including all
but my own conflicts i.e. my trigger clicks doesn't lets this happen and code gets into loop between All checkbox checked clicks and single checkbox click
I have created JS Fiddle.
In short I need toggle from checkbox button as well if all are selected on click on one of the checkbox it should make that one selected and rest all unselected
Here is the jQuery code
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js"></script>
<script>
jQuery(window).ready(function() {
//check ALl checkbox onClick
jQuery('body').on('click', '.chktaxoall,.chkcmfall',function (e) {
if(this.checked){
var i = 0;
var sList;
jQuery(this).closest('.togglecheck').find('input:checkbox').each(function () {
var sThisVal = (this.checked ? "1" : "0");
i++;
if(sThisVal==0 && i>1){
jQuery(this).trigger('click','bot');
}
});
}
else{
jQuery(this).closest('.togglecheck').find('input:checkbox').prop('checked', this.checked);
}
});
//IF ALL IS SELECTED but if a user clicks on a particular checkbox uncheck all except the one user checked
jQuery('body').on('click', '.wrap_acf input:checkbox',function (e) {
//if all is checked and someone unchecks a checkbox make all uncheck
var thisParent=jQuery(this).parents('.uwpqsf_class').attr('id');
var AllTicked =jQuery("#"+thisParent+" .chkcmfall").prop('checked');
if(thisParent && AllTicked){
jQuery("#"+thisParent+" .chkcmfall").prop('checked',false)
//jQuery(this).trigger('click');
}
})
});
</script>
Here is the HTML structure
<div id="mycategory" class="filter_acc_class uwpqsf_class togglecheck">
<h2 class="LabelPlaceHolder">Category</h2>
<!-- Add controlall and data-boxid -->
<label class="searchLabel control controlAll checkbox" data-boxid="wrap_id_cats"><input type="checkbox" class="chkcmfall" value="" name="mycatname[]" data-boxid="wrap_id_cats"><span class="control-indicator"></span>All</label>
<div id="wrap_id_cats" class="wrap_acf togglecheck">
<label class="searchLabel control checkbox"><input type="checkbox" value="16" name="mycatname[]"><span class="control-indicator"></span>Bakery<span class="fltr_num">(12)</span></label><br>
<label class="searchLabel control checkbox"><input type="checkbox" value="18" name="mycatname[]"><span class="control-indicator"></span>Indulgences<span class="fltr_num">(12)</span></label><br>
<label class="searchLabel control checkbox"><input type="checkbox" value="17" name="mycatname[]"><span class="control-indicator"></span>Dairy<span class="fltr_num">(7)</span></label><br>
<label class="searchLabel control checkbox"><input type="checkbox" value="19" name="mycatname[]"><span class="control-indicator"></span>Meat<span class="fltr_num">(7)</span></label><br>
<label class="searchLabel control checkbox"><input type="checkbox" value="27" name="mycatname[]"><span class="control-indicator"></span>test4<span class="fltr_num">(7)</span></label><br>
<label class="searchLabel control checkbox"><input type="checkbox" value="24" name="mycatname[]"><span class="control-indicator"></span>test1<span class="fltr_num">(5)</span></label><br>
<label class="searchLabel control checkbox"><input type="checkbox" value="26" name="mycatname[]"><span class="control-indicator"></span>test3<span class="fltr_num">(5)</span></label><br>
<label class="searchLabel control checkbox"><input type="checkbox" value="25" name="mycatname[]"><span class="control-indicator"></span>test2<span class="fltr_num">(1)</span></label><br>
<label class="searchLabel control checkbox"><input type="checkbox" value="29" name="mycatname[]"><span class="control-indicator"></span>test6<span class="fltr_num">(1)</span></label><br>
<label class="searchLabel control checkbox"><input type="checkbox" value="30" name="mycatname[]"><span class="control-indicator"></span>test7<span class="fltr_num">(1)</span></label>
</div>
</div>