admin管理员组文章数量:1415652
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?
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?
Share Improve this question edited Sep 7, 2015 at 12:07 Karmalakas asked Sep 7, 2015 at 11:49 KarmalakasKarmalakas 1,1412 gold badges20 silver badges43 bronze badges 5- Could you attach a minimal example? JSFiddle – Ramiz Wachtler Commented Sep 7, 2015 at 11:56
- @RamisWachtler, edited a question. As You can see, it doesn't matter if I confirm or not, input still gets toggled. – Karmalakas Commented Sep 7, 2015 at 12:08
-
So, if you ask 'Dont check?' the initial checkbox state is
unchecked
? – Ramiz Wachtler Commented Sep 7, 2015 at 12:33 - You can change a question to "Don't toggle?" if You like it better :) But yes. – Karmalakas Commented Sep 7, 2015 at 12:39
- 1 That's a pain in the a** :D All I could find out it this – Ramiz Wachtler Commented Sep 7, 2015 at 12:59
2 Answers
Reset to default 4So 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.
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./ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<link href="https://cdnjs.cloudflare./ajax/libs/iCheck/1.0.1/skins/flat/flat.css" rel="stylesheet"/>
<link href="https://cdnjs.cloudflare./ajax/libs/iCheck/1.0.1/skins/all.css" rel="stylesheet"/>
<script src="https://cdnjs.cloudflare./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.
本文标签: javascriptiCheck pluginifToggled cancel eventStack Overflow
版权声明:本文标题:javascript - iCheck plugin - ifToggled cancel event - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745176675a2646271.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论