Anyone having problems with javascript or jquery checkbox AdminLTE bootstrap framework ? Problems such as the onclick event is not working, checked method doesn’t work and others. Yes, I am one of those people who are confused using the checkbox on the framework.
Admin LTE is an absolutely stunning free Bootstrap dashboard theme from almsaeedstudio. It is fully responsive and built on top of Bootstrap 3 . Read here for more information.
Table of Contents
The problem that occurs is when we write the code in jquery or javascript, but the script can not run and there is no error in the checkbox adminLTE function .
The reason is javascript function that set the display of checkbox. That functions are located on the file AdminLTE / app.js at line 136.
1 2 3 4 5 6 7 8 9 | /* * We are gonna initialize all checkbox and radio inputs to * iCheck plugin in. * You can find the documentation at http://fronteed.com/iCheck/ */ $("input[type='checkbox']:not(.simple), input[type='radio']:not(.simple)").iCheck({ checkboxClass: 'icheckbox_minimal', radioClass: 'iradio_minimal' }); |
It’s not a bug or error in checkbox adminLTE bootstrap, but we are less keen in using adminLTE framework. Checkbox and radio inputs in adminLTE using iCheck plugin. We can find the documentarion at http://fronteed.com/iCheck/
According fronteed.com, iCheck provides plenty callbacks, which may be used to handle changes.
Callback name When used ifClicked user clicked on a customized input or an assigned label ifChanged input’s checked, disabled or indeterminate state is changed ifChecked input’s state is changed to checked ifUnchecked checked state is removed ifToggled input’s checked state is changed ifDisabled input’s state is changed to disabled ifEnabled disabled state is removed ifIndeterminate input’s state is changed to indeterminate ifDeterminate indeterminate state is removed ifCreated input is just customized ifDestroyed customization is just removed
We need use on() method to bind them to inputs like example below :
1 2 3 | $('input').on('ifChecked', function(event){ alert(event.type + ' callback'); }); |
ifCreated callback must be binded before plugin init.
Methods, these methods can be used to make changes programmatically (any selectors can be used).
$(‘input’).iCheck(‘check’); — change input’s state to checked
$(‘input’).iCheck(‘uncheck’); — remove checked state
$(‘input’).iCheck(‘toggle’); — toggle checked state
$(‘input’).iCheck(‘disable’); — change input’s state to disabled
$(‘input’).iCheck(‘enable’); — remove disabled state
$(‘input’).iCheck(‘indeterminate’); — change input’s state to indeterminate
$(‘input’).iCheck(‘determinate’); — remove indeterminate state
$(‘input’).iCheck(‘update’); — apply input changes, which were done outside the plugin
$(‘input’).iCheck(‘destroy’); — remove all traces of iCheck
Lets try my simple code below, how to use checkbox adminLTE dashboard framework.
[sociallocker id=”58″]
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 | <html> <head> <meta charset="UTF-8"> <title>How to use checkbox event in adminLTE dashboard framework</title> <meta content='width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no' name='viewport'> <link href="../css/bootstrap.min.css" rel="stylesheet" type="text/css" /> <link href="../font-awesome-4.1.0/css/font-awesome.min.css" rel="stylesheet" type="text/css" /> <link href="../css/AdminLTE.css" rel="stylesheet" type="text/css" /> </head> <body class="skin-black"> <div class="wrapper row-offcanvas row-offcanvas-left"> <aside class="right-side"> <section class="content-header"> <h1> How to use checkbox event in adminLTE dashboard framework </h1> </section> <section class="content"> <div class="box box-primary"> <div class="box-body"> <h4>Default Category</h4> <div class="form-group"> <textarea class="form-control" id="dataarray" disabled="disabled" rows="5" cols="50"></textarea> </div> <div class="form-group"> <div class="row"> <?php $defcat=explode(",","google,bing,yahoo,ask.com,baidu,seegatesite.com"); for($i=0;$i<count($defcat);$i++) { if($i==0){ echo '<div class="col-xs-8 col-md-2">'; } if($i==10){ echo '<div class="col-xs-8 col-md-2">'; } echo '<div class="checkbox"><label >'; echo '<input type="checkbox" class="check" id="check_kat_'.$i.'" value="'.$defcat[$i].'"> '.$defcat[$i]; echo '</label></div>'; if($i==9){ echo '</div>'; } if($i==19){ echo '</div>'; } if($i==count($defcat)){ echo '</div>'; } } ?> </div> </div><button id="checkallkat" onClick="check_all_kategori(<?php echo count($defcat)?>);" type="button" class="btn btn-primary" title="Check all">Check All</button> </div> </div> </div> </section> </aside> </div> <script src="../js/jquery.min.js"></script> <script src="../js/bootstrap.min.js" type="text/javascript"></script> <script src="../js/AdminLTE/app.js" type="text/javascript"></script> <script language="javascript"> function check_all_kategori(jumarray) { if (document.getElementById("checkallkat").innerHTML == "Check All") { for( var i=0;i<jumarray;i++) { $('.check').iCheck('check'); } document.getElementById("checkallkat").innerHTML = "Uncheck All" }else { for( var i=0;i<jumarray;i++) { $('.check').iCheck('uncheck'); } document.getElementById("checkallkat").innerHTML = "Check All" } implode_kategori(jumarray); } $('.check').on('ifChanged', function(){ implode_kategori(6); }); </script> <script> function implode_kategori(jumarray) { var array=[]; var n=0; for( var i=0;i<jumarray;i++) { check_name='check_kat_'+i.toString(); if(document.getElementById(check_name).checked == true) { array[n]=document.getElementById(check_name).value; n = n+1; } } var kat_join = array.join(); document.getElementById('dataarray').innerHTML=kat_join; } </script> </body> </html> |
[/sociallocker]
Read more my bootstrap article here
Thanks.
Thanks Man
Thanks for the article. Saved me lot of time. I just couldn’t figure out why jQuery for Checkbox was failing in Admin LTE.
not failing, because checkbox in LTE not handle by jquery but handle in LTE script.
Life saver 🙂
grazie non riuscivo a capire
any way to disable the iCheck plugin?