drgullin / icheck

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

Duplicate iCheck object generated on v2.0 RC #154

Closed steventen closed 9 years ago

steventen commented 10 years ago

Hi,

I noticed a problem: When iCheck was initialized more than once on the same selectors, the code will generate more iCheck box, even though it was generated before.

The code I'm using looks like this (and of course if it's in v2.0, it will be icheck with lowercase):

$('input[type="checkbox"].square-grey').iCheck({
  checkboxClass: 'icheckbox_square-grey',
  radioClass: 'iradio_square-grey',
  increaseArea: '10%' // optional
});

But this does not happen on v1.0

drgullin commented 10 years ago

Thanks, I'll check this.

drgullin commented 9 years ago

This doesn't happen in current version of 2.x.

JayAdra commented 9 years ago

This is still happening for me in the latest 2.x. I am using a custom init() function which runs after ajax calls are made, so the inputs are iCheck'd dynamically.

This works fine (and works perfectly in 1.x), except in 2.x it creates duplicate iCheck elements.

Can you please look back into this one?

UPDATE: Something else I discovered - it seems when I run the init() function a second time, there are no duplicate checkbox elements created. But then the third and subsequent times, it creates an extra element. Not sure why...

drgullin commented 9 years ago

Show me the code you use with iCheck, please.

JayAdra commented 9 years ago
//Checkbox
var check_target_class = "input:not(.no-touchy):not(.icheck-input)";
var check_options = {
    checkboxClass: "check-it icheckbox_flat-blue",
    radioClass: "check-it iradio_flat-blue"
};

//Initialise custom checkboxes
$(check_target_class).icheck(check_options);

I forgot to mention - I added the :not selector to temporarily fix the duplicate issue. But I'd like to be able to have this work natively if possible.

AtomStar commented 9 years ago

I also have the same problem. Extra checkboxes are created when the following code is called multiple times:

 if ($('input[type="checkbox"]').length || $('input[type="radio"]').length) {
            $('input[type="checkbox"].grey, input[type="radio"].grey').icheck({
                checkboxClass: 'icheckbox_minimal-grey',
                radioClass: 'iradio_minimal-grey',
                increaseArea: '10%' // optional
            });
            $('input[type="checkbox"].red, input[type="radio"].red').icheck({
                checkboxClass: 'icheckbox_minimal-red',
                radioClass: 'iradio_minimal-red',
                increaseArea: '10%' // optional
            }); 
 }