Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iCheck plugin - ifToggled cancel event

Is it possible to cancel action of iCheck on ifToggled? I have unchecked input:

$('input').iCheck().on('ifToggled', function(e) {
    if (confirm('Don\'t check?')) {
        return false;
    }
});

Input still gets checked (JSFiddle simple example). Is there any way to cancel event?

like image 316
Karmalakas Avatar asked Sep 07 '15 11:09

Karmalakas


1 Answers

So I had to stick with not so nice workaround using a timeout

$('input').iCheck({
    checkboxClass: 'icheckbox_flat'
}).on('ifToggled', function(e) {
    if ($('input').is(':checked') && confirm('Don\'t check?')) {
        setTimeout(function() {
           $('input').iCheck('uncheck');
        }, 50);
    }
});

JSFiddle

If anyone has a better solution, would love to hear it.

like image 121
Karmalakas Avatar answered Oct 27 '22 08:10

Karmalakas