Giter VIP home page Giter VIP logo

bootstrap-checkbox-x's Introduction

Krajee Logo
bootstrap-checkbox-x
Donate       kartikv

Bower version Latest Stable Version License Packagist Downloads Monthly Downloads

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.

With v1.5.5, the plugin now supports initializing widget on a SELECT input as well (other than a CHECKBOX or TEXT input).

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.

Features

  1. Enhances any HTML input (preferrably a checkbox or text input) with data-toggle=checkbox-x to an extended checkbox control.
  2. 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.
  3. You can set the plugin to allow three states or the default two states for the checkbox.
  4. 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.
  5. 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.
  6. Plugin CSS styling automatically defaults the checkboxes to inline display. You can also control the markup for block display like in checkbox lists.
  7. 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.
  8. Ability to navigate to the checkbox controls via keyboard, and modify the values using the space bar on the keyboard.
  9. Ability to size the checkbox control. Five prebuilt size templates are available xl, lg, md, sm, and xs.
  10. 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.
  11. Ability to access methods and refresh the input dynamically via javascript at runtime.
  12. Disabled and readonly checkbox input support.
  13. Allow third state to be configured (only on init) for two state checkboxes.
  14. 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.

Documentation and Demo

View the plugin documentation and plugin demos at Krajee JQuery plugins.

Pre-requisites

  1. Bootstrap 5.x or 4.x or 3.x
  2. Latest JQuery
  3. Most browsers supporting CSS3 & JQuery.

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.

Installation

Using Bower

You can use the bower package manager to install. Run:

bower install bootstrap-checkbox-x

Using Composer

You can use the composer package manager to install. Either run:

$ php composer.phar require kartik-v/bootstrap-checkbox-x "@dev"

or add:

"kartik-v/bootstrap-checkbox-x": "@dev"

to your composer.json file

Manual Install

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.

Usage

Step 1: Load the following assets in your header.

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css">
<link href="https://cdn.jsdelivr.net/gh/kartik-v/[email protected]/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/[email protected]/js/checkbox-x.min.js"></script>
<!-- optional if you are using themes -->
<link href="https://cdn.jsdelivr.net/gh/kartik-v/[email protected]/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.

Step 2: Setup your input markup with data-toggle="checkbox-x" to automatically initialize the checkbox control

<input type="checkbox" id="input-id" value="1" checked data-toggle="checkbox-x" data-three-state="true" data-size="lg" >

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,

<!-- enclose the checkbox input & label in container with class `cbx-krajee`
  -- and also add the `cbx-label` class to your checkbox labels -->

<div class="cbx-krajee">
   <input id="input-id" type="checkbox" value="1" checked>
   <label for="input-id" class="cbx-label"></label>
</div>

<script>
$(document).on("ready", function() {
    // initialize with defaults
    $("#input-id").checkboxX();

    // with plugin options
    $("#input-id").checkboxX({threeState: true, size:'lg'});
});
</script>

The #input-id is the identifier for the input on your page, which is hidden automatically by the plugin.

Alternatively, you can directly call the plugin options by setting data attributes to your input field.

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).

License

bootstrap-checkbox-x is released under the BSD 3-Clause License. See the bundled LICENSE.md for details.

bootstrap-checkbox-x's People

Contributors

baptistedonaux avatar kartik-v avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

bootstrap-checkbox-x's Issues

Tabindex - why not 0?

Hi

If I place a bootstrap-checkbox-x in the middle of several inputs, then using TAB skips the bootstrap-checkbox-x until the end of last control.

Why not use tabindex="0"? This way it will follow the flow?

Thanks

Keeps returning 404 Not Found Error

I've downloaded the zip file twice. I made sure to expand the zip file. I unlocked each of the .js files, made sure to put them in the /js/ folder, and I'm using a basic tag <script src="/js/checkbox-x.min.js"></script> yet no matter what, the file shows as 404, not found, even when trying to load the file directly via my browser.

Native checkbox does not retain correct properties

For 2-state checkboxes, you have to rely on val() being either "1" or "0" to determine whether a Checkbox-X box is indeed checked. This is because checkbox-x does not seem to correctly set the underlying properties on the native checkbox.

For example, on your demo page (http://plugins.krajee.com/checkbox-x/demo), open up the console and run these tests:

> ("#input-20").val()
"1"
> $("#input-20").is(':checked')
false
> $("#input-20").checked
false

This is also a problem if you want the value to be something else – e.g. "on" or "yes" or whatever.

Default Value

Hi, it seems checkbox has 4 states instead of 3.

  1. Default value is empty.
  2. Checked is 1
  3. NonChecked is 0
  4. null is null

In mysql this is not a problem, cause empty and cero is the same. But in PostgreSQL make it crash,

Unable to unselect checkbox after setting val(1)

Hi,

like the title says I'm not able to unselect a checkbox after selecting it via javascript:

// checking it
$( '#option' ).val(1);
$( '#option' ).checkboxX('refresh');
$( '#option' ).trigger('change');

The change event is fired twice, which is probably the problem.
Without checking the checkbox via javascript it works like expected. The attribute data-enclosed-label is already set to true.

Thanks for your help in advance.

encodeLabel possible?

Sorry, was looking for this feature in the documentation, but did not find.

Is it possible to use something like 'encodeLabel' => false, to allow using HTML tags in label text?

Dynamically change Checked | Unchecked states

Hello
Need to simply switch all the checkboxes Checked / Unchecked

    var chkbx = $("input[sub_checkbox*='true']");
    if ($(this).val() == '0') {
        $.each(chkbx, function(index, value) {
            $(this).checkboxX("refresh", {valueChecked: '1'});
        });
    } else {
        $.each(chkbx, function(index, value) {
            $(this).checkboxX("refresh", {valueUnchecked: '1'});
        });
    }

Checkbox just holds and they do not switch. Is this a right behaviour ?

custom values not working

Hi Kartik, thanks for this plugin.
I'm trying to use the custom value but after declared the pluging doesn't works as aspeceted. When i check the checkbox the flag doesn't apper and the value is not updated.

Thanks
the code here:

$("chk") .checkboxX({
size: 'md',
threeState: false,
valueChecked: 'true',
valueUnchecked: 'false'
});

Doubleclick markes the line

When I double click a checkbox, then the whole row is marked blue:

Image of Yaktocat

Is it possible to detect doubleclick and then set selectionlength to 0?

Thx

How can I check a 'checkbox-x' checkbox using Javascript?

Hi guys,

Like the title says, is it possible to check a 'checkbox-x' checkbox using Javascript? Here's what I've tried:

$("#checkAllButton").on('click', function() {
    $(".accessoryCheckbox").val('1');
});

Where all my checkbox-x checkbox's have the accessoryCheckbox class on them.

Element's binding on 'click' reverts the action

Demo: http://jsfiddle.net/1uc4feys/10/

Setup like $el.checkboxX({'threeState': false, 'labelClickEvent':false}); causes a revert of the just changed value because of the event listener for 'click' on $element.

The visual effect is: the checkbox doesn't change its state.
With debugger I can see that it changes from on to off and then from off to on again.

Checkbox not be changed

Libs:
jQuery v2.1.1
Bootstrap v3.3.1

Options:

$("input[type=checkbox]").checkboxX({
    threeState: false,
    size: 'xs',
    inline: true
});

-- fix --

change: function () {
    .....
    $el.val(newVal);
    $el.trigger('change');

    if () {
        ...
    }
    .....
}

to

change: function () {
    .....

    if () {
        $el.val(newVal);
        $el.trigger('change');
    }
    .....
}

Two possible + set indeterminate

Is it possible to have a behavior like the standard checkbox?
While clicking it it only has two possible states (checked / unchecked) but it is possible to set it to indeterminate via javascript.
Something like:
http://jsbin.com/wojujequxa/6/edit?html,js,output

just with the plugin's nice styling.

btw I tried to use the plugin in jsbin but it failed. I can see the changed markup (cbx-container etc.), but the new styling is not applied

Bower Install is broken

Hi,

with your commit 87ff3e0 the bower install command doesn't work as expected.

If you now try to install the package the npm pull the wrong bootstrap version.

I used nodejs in version 4.0.0 and 4.1.0.

Note:
http://fredkschott.com/post/2014/02/npm-no-longer-defaults-to-tildes/

"C:\Users\AppData\Roaming\npm\bower.cmd" "install"
bower bootstrap-checkbox-x#1.5.4 cached git://github.com/kartik-v/bootstrap-checkbox-x.git#1.5.4
bower bootstrap-checkbox-x#1.5.4 validate 1.5.4 against git://github.com/kartik-v/bootstrap-checkbox-x.git#1.5.4
bower bootstrap#~3.0 cached git://github.com/twbs/bootstrap.git#3.0.3
bower bootstrap#~3.0 validate 3.0.3 against git://github.com/twbs/bootstrap.git#~3.0

regards
j0inty

Provide a means to update visual state of checkbox

Right now there is no way to update visual state of checkbox control if underlying checkbox was modified through DOM manipulations.
This is very unconvinient in situations where 2-way bindings are involved like in Angular.
Can you please add some method to simply refresh control's internal state based on checkbox's current state?

Dual-state does not work when type="checkbox" specified

Working on 1.4.0, if my input has type="checkbox" specified, three-state checkboxes work as expected, while dual-state don't.

After some debugging, it seems that the checkbox switches back to its original value, after the 'change' event gets re-triggered at line #82, due to flag being 0. Adding an extra check on line 81 for self.options.threeState seems to solve the issue for me, but I'm not sure if it's breaking something else.

if (!flag && !useNative && self.options.threeState) {
    $el.trigger('change');
}

API Checkbox Change Event Not Firing

Hi all,

I'm trying to set an event to fire when the checkbox-x element changes, but I can't seem to get it to work. What am I doing wrong?

$(".accessoryCheckbox").on('rating.change', function() {
    alert('test');
});

Get Class checkbox-x

Hi You. I using bootstrap-checkbox-x. I have .I want take class "Demo" and add to div.class"cbx ".

Not working with angularJS app

When I add the data attribute to a checkbox inside my ng-app, nothing happens. Adding the checkbox in the index file works fine, but I need it of course inside my ng-views.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.