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?
Throwing an exception seems to cancel the event propagation:
$('input').iCheck({
checkboxClass: 'icheckbox_flat'
}).on('ifToggled', function(e) {
if ($('input').is(':checked') && confirm('Don\'t check?')) {
throw "canceled";
}
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/iCheck/1.0.1/skins/flat/flat.css" rel="stylesheet"/>
<link href="https://cdnjs.cloudflare.com/ajax/libs/iCheck/1.0.1/skins/all.css" rel="stylesheet"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/iCheck/1.0.1/icheck.min.js"></script>
<label>Input <input type="checkbox" value="1" name="input"/></label>
PS: I don't like this approach, but it works.