drgullin / icheck

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

Why can't use a callback func when initialize iCheck? #137

Closed kntmrkm closed 10 years ago

kntmrkm commented 10 years ago

Hello. I'm using this great JS lib in Rails app.

I want to catch callback event in below code,

in app/assets/javascripts/form.js

$(function() {
  $('input').on('ifToggled', function(event){
    console.log("test");
  });
});

and, I discribed initial code below.

in app/assets/javascripts/init-icheck.js

$(function() {
  init_icheck();
  $(document).on('ready page:change', init_icheck);
});

init_icheck = function(){
  $('input').iCheck({
    checkboxClass: 'icheckbox_square-green',
    radioClass: 'iradio_square-green'
  });
};

I could confirm callback working finally. but, It's working when delete below part.

in app/assets/javascripts/init-icheck.js

  $(document).on('ready page:change', init_icheck);

above code initialize callback function? if not delete above part. "ifToggled" event doesn't work.

but, my app(Rails) need initializing iCheck when change a page. How do I should fix my code?

Enviroment is below.

sorry, my english.

thank you.

kntmrkm commented 10 years ago

sorry guys.

problem cause this part.

$(function() {
  init_icheck();
  $(document).on('ready page:change', init_icheck);
});

no need init_icheck();. initializing process duplicated. maybe.