An extended checkbox plugin for Bootstrap built using JQuery, which allows three checkbox states and includes additional styles. The plugin uses Bootstrap markup and CSS 3 styling by default, but it can be overridden with any other CSS markup. It also helps you to fallback to a native checkbox OR display native checkboxes with tristate capability., (*1)
With v1.5.5, the plugin now supports initializing widget on a SELECT input as well (other than a CHECKBOX or TEXT input)., (*2)
NOTE: The checkbox plugin stores the values by default as character format (and not boolean format) for checked and unchecked states. This can be overridden by setting valueChecked, valueUnchecked and valueNull properties., (*3)
Features
Enhances any HTML input (preferrably a checkbox or text input) with data-toggle=checkbox-x to an extended checkbox control.
The plugin offers the following three states and values for the checkboxes:
'1': Checkbox is checked. This value is configurable through valueChecked property.
'0': Checkbox is unchecked. This value is configurable through valueUnchecked property.
'': Checkbox is indeterminate. This value is configurable through valueNull property.
You can set the plugin to allow three states or the default two states for the checkbox.
Specifically uses Bootstrap 5.x or 4.x or 3.x styles. One can configure the checked, unchecked, and indeterminate icons to be shown for the checkboxes.
Special CSS 3 styling, to enhance the control to look like any Bootstrap 3 form control. Supports the has-error, has-success, has-warning
styling states like other Bootstrap form-controls.
Plugin CSS styling automatically defaults the checkboxes to inline display. You can also control the markup for block display like in checkbox lists.
You can add a label before or after with a for attribute and click on the label to change the checkbox values. Alternatively you can enclose the
input within a label tag as well.
Ability to navigate to the checkbox controls via keyboard, and modify the values using the space bar on the keyboard.
Ability to size the checkbox control. Five prebuilt size templates are available xl, lg, md, sm, and xs.
Triggers JQuery events for advanced development. The plugin automatically triggers the change event for the input, whenever the checkbox value is changed via clicking. Events currently available are change and checkbox.reset.
Ability to access methods and refresh the input dynamically via javascript at runtime.
Disabled and readonly checkbox input support.
Allow third state to be configured (only on init) for two state checkboxes.
Added support for displaying native checkboxes with tristate capability. When displaying native checkboxes, the advanced styling offerred by the plugin will not be available.
NOTE: The latest version of the plugin v1.5.7 has been released. Refer the CHANGE LOG for details., (*4)
NOTE: You can use the sass branch for installation using bootstrap-sass dependency. The master branch can be used for installation using the default official bootstrap dependency., (*6)
Installation
Using Bower
You can use the bower package manager to install. Run:, (*7)
bower install bootstrap-checkbox-x
Using Composer
You can use the composer package manager to install. Either run:, (*8)
You can also manually install the plugin easily to your project. Just download the source ZIP or TAR ball and extract the plugin assets (css and js folders) into your project., (*11)
Usage
Step 1: Load the following assets in your header., (*12)
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.1/dist/css/bootstrap.min.css">
<link href="https://cdn.jsdelivr.net/gh/kartik-v/bootstrap-checkbox-x@1.5.7/css/checkbox-x.min.css" media="all" rel="stylesheet" type="text/css" />
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script src="https://cdn.jsdelivr.net/gh/kartik-v/bootstrap-checkbox-x@1.5.7/js/checkbox-x.min.js"></script>
<!-- optional if you are using themes -->
<link href="https://cdn.jsdelivr.net/gh/kartik-v/bootstrap-checkbox-x@1.5.7/css/theme-krajee-flatblue.min.css" media="all" rel="stylesheet" type="text/css" />
If you noticed, you need to load the jquery.min.js and bootstrap.min.css in addition to the checkbox-x.min.css and checkbox-x.min.js for
the plugin to work with default settings. Loading the theme file theme-krajee-flatblue.min.css is optional and is needed if you want to override the default theme. Read the theme property of the plugin for understanding configuration details for themes., (*13)
Step 2: Setup your input markup with data-toggle="checkbox-x" to automatically initialize the checkbox control, (*14)
Step 3: You can also initialize the plugin on your page using javascript as well, instead of using data-toggle attribute as above. For example,, (*15)
The #input-id is the identifier for the input on your page, which is hidden automatically by the plugin., (*16)
Alternatively, you can directly call the plugin options by setting data attributes to your input field., (*17)
Note: You should wrap the input and label in a container with CSS class cbx-krajee for better alignment. You should also add the CSS class cbx-label to the labels for your checkbox inputs to style them similar to bootstrap's checkbox labels (which includes additional enhancements for contextual colors)., (*18)
License
bootstrap-checkbox-x is released under the BSD 3-Clause License. See the bundled LICENSE.md for details., (*19)