Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use iCheck with Live #37

Closed
billmn opened this issue May 22, 2013 · 3 comments
Closed

How to use iCheck with Live #37

billmn opened this issue May 22, 2013 · 3 comments

Comments

@billmn
Copy link

billmn commented May 22, 2013

How can I apply iCheck to checkboxes/radios loaded from ajax?
In a normal HTML page works fine, but if I load this page from ajax, iCheck isn't applied.

I'm using this code :

$('input[type=checkbox], input[type=radio]').iCheck({
    checkboxClass: 'icheckbox_square-blue',
    radioClass: 'iradio_square-blue'
});

Cheers

@pocesar
Copy link

pocesar commented May 22, 2013

create a delegated function that applies your iCheck, then call it later from the AJAX callback

$(document).on('icheck', function(){
  $('input[type=checkbox], input[type=radio]').iCheck({
    checkboxClass: 'icheckbox_square-blue',
    radioClass: 'iradio_square-blue'
  });
}).trigger('icheck'); // trigger it for page load

then in your AJAX

$.ajax(...).done(function(){
  // deal with your data
  $(document).trigger('icheck'); // apply icheck to checkboxes
});

Of course, you can just set a global function that does that, but cluttering the global space isn't a good idea

@billmn
Copy link
Author

billmn commented May 22, 2013

Works fine! thank you

@billmn billmn closed this as completed May 22, 2013
@rumends
Copy link

rumends commented Jul 26, 2013

There is a little problem whit this delegation.
If you use
$('#mycheckbox').on('ifToggled', function(){
// custom function
});
to bind custom function to specific checkbox after ajaxs trigger 'icheck' there is no bind function to $('#mycheckbox')
Is there any solution for this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants