HTML Section
<div class="right-part ap-search-8">
<h5 class="insta-search-head"><?php echo \Application\Plugin\Common::z_xlt('Instant Search Filters'); ?>:</h5>
<label class="tag alltags" title="<?php echo \Application\Plugin\Common::z_xlt('All Tags'); ?>">
<input type="checkbox">
<span class="tag-text"><?php echo \Application\Plugin\Common::z_xlt('All Tags'); ?></span>
</label>
<?php
$default_filters = (empty($GLOBALS['zhemr']['default_patient_search_filters'])) ? array('fname|lname|mname','pd_pid'): (array)$GLOBALS['zhemr']['default_patient_search_filters']; ?>
<label class="tag <?php if(in_array('fname|lname|mname',$default_filters)){ ?>ap-search-9<?php }?>" data-filter="fname|lname|mname" title="<?php echo \Application\Plugin\Common::z_xlt('Name'); ?>">
<input type="checkbox">
<span class="tag-text"><?php echo \Application\Plugin\Common::z_xlt('Name'); ?></span>
</label>
<label class="tag <?php if(in_array('pd_pid',$default_filters)){ ?>ap-search-9<?php }?>" data-filter="pd_pid" title="<?php echo \Application\Plugin\Common::z_xlt('PID'); ?>">
<input type="checkbox">
<span class="tag-text"><?php echo \Application\Plugin\Common::z_xlt('PID'); ?></span>
</label>
<?php foreach($this->filters as $field_id => $filter) :
?>
<label class="tag <?php if(in_array($field_id,$default_filters)){ ?>ap-search-9<?php }?>" data-filter="<?php echo $field_id; ?>" title="<?php echo \Application\Plugin\Common::z_xlt($filter); ?>">
<input type="checkbox">
<span class="tag-text"><?php echo \Application\Plugin\Common::z_xlt($filter); ?></span>
</label>
<?php
endforeach;
?>
</div>
JS Section
$(".ap-search-8 .tag").click(function(ev) {
if (!$(this).hasClass("alltags")) {
ev.preventDefault();
if ($(this).hasClass("ap-search-9")) {
if ($(".ap-search-9").length < 2) return;
$(this).removeClass("ap-search-9");
$(this).removeClass("ap-search-adv");
$(this).find("input[type='checkbox']").removeAttr('checked');
} else {
$(this).addClass("ap-search-9");
$(this).addClass("ap-search-adv");
$(this).find("input[type='checkbox']").attr('checked', "checked");
}
} else {
if ($(this).find("input[type='checkbox']").is(":checked")) {
//$(".ap-search-8 .tag").not(".alltags").addClass('ap-search-9');
$(".ap-search-8 .tag").not(".alltags").addClass('ap-search-9').find("input[type='checkbox']").attr('checked', "checked");
} else {
//(".ap-search-8 .tag").not(".alltags").removeClass('ap-search-9');
$(".ap-search-8 .tag").not(".alltags,[data-filter='fname|lname|mname'],[data-filter='pd_pid']").removeClass('ap-search-9').find("input[type='checkbox']").removeAttr('checked');
}
}
var filter_fields = "";
var i = 0;
top.$(".ap-search-9").each(function() {
i++;
if (filter_fields != '') filter_fields += "****";
filter_fields += $(this).attr("data-filter");
});
if ($('.ap-search-8').find('.ap-search-9').length == $('.ap-search-8').find('label.tag').not('.alltags').length) {
$('.ap-search-8').find('.alltags').find("input[type='checkbox']").prop('checked', 'true');
} else {
$('.ap-search-8').find('.alltags').find("input[type='checkbox']").removeAttr('checked');
}
angular.element($('#angular_jquery_map')).scope().filterFields = filter_fields;
requestRunning = true;
memorizeSearchFilters();
return false;
});
Here the click function happens twice for 'Alltags' label and also for other labels it works properly. If we put the preventDefault() function outside the if condition then the clicks become ok but the else part ie, click wrote for 'Alltags' doesnt work. The checkbox check and uncheck not happens. If anyone Knows the solution please help.