drgullin / icheck

Highly customizable checkboxes and radio buttons (jQuery & Zepto)
http://fronteed.com/iCheck
7.38k stars 1.62k forks source link

multiple checked and unchecked event #107

Closed magna25 closed 10 years ago

magna25 commented 10 years ago

I like the plugin however I am facing a prob with checked and unchecked state. I have a text which I need to display when checkbox is checked and hide it if it is not. I was able to do this by using the below

$('input').on('ifChecked', function(event){
   $(".text").show();
});
$('input').on('ifUnchecked', function(event){
   $(".text").hide();
});

The above code works however I want only to hide the text if ALL CHECKBOXES are unchecked so how do I accomplish this? Any other event except the plugin does not work.

drgullin commented 10 years ago

You can do this:

$('input').on('ifUnchecked', function(event) {
  var unchecked = true;

  $('input[name="' + this.name + '"]').each(function() {
    this.checked && (unchecked = false);
  });

  unchecked && $(".text").hide();
});
magna25 commented 10 years ago

This does not work. Do you have any other solution? I really need this feature.

magna25 commented 10 years ago

Once checked the I can not uncheck them again.

drgullin commented 10 years ago

This task isn't related to iCheck, you may try to ask for a solution on stackoverflow instead. Anyway, I can't help until you provide a demo.

magna25 commented 10 years ago

yes it is related to icheck if I disable the plugin I am able to achieve what I want. Check out the fiddle here http://jsfiddle.net/vFmXz/6/ disable the plugin and click on the checkboxes and see what happens again enable it and see what happens. iCheck overrides other events.

drgullin commented 10 years ago

Oops, I forgot brackets. See the updated code https://github.com/fronteed/iCheck/issues/107#issuecomment-31120359 Here's a quick demo http://jsfiddle.net/GLcu7/