Giter Site home page Giter Site logo

deep-checkbox's Introduction

jQuery plugin that brings some logic to nested checkboxes

Imagine multidimensional list with checkboxes. They are nested in LI-elements (by the way, nesting is necessary for this plugin work).

Child-checkboxes are inherit parent's property, so when checking or unchecking a parent checkbox, Deep Checkbox will automatically check or uncheck all child elements as well.

Users can also select or deselect just specific items, and the plugin will be able to tell what items are actually selected in your complex tree hierarchy and where are they place inside the branches.

Besides this check/uncheck logic, the Deep Checkbox plugin also provides programmatic functions or getting which items are selected and which were left unchecked or excepted from a previously grouped selection.

You can see demo here.

Plugin should be called to selector wrapping whole list:

<div class="wrapper">
    <ul>
        <li>
            <input type="checkbox" data-id="item" data-name="Item" /> Item
            <ul>
                <li><input type="checkbox" data-id="subitem1" data-name="Subitem 1" /> Subitem 1</li>
                <li><input type="checkbox" data-id="subitem2" data-name="Subitem 2" /> Subitem 2</li>
                <li><input type="checkbox" data-name="Subitem 3" /> Subitem 3</li>
            </ul>
        </li>
    </ul>
</div>
    
<script>
    $('.wrapper').deepcheckbox();
</script>

Plugin can be called with following options:

$('.wrapper').deepcheckbox({
    readableListTarget: '.selector', // Selector for element(s), where will be displayed readable text with checked items
    listItemBefore: '<span class="item">', // Prefix before each item in readable list
    listItemAfter: '</span>', // Suffix after each item in readable list
    listItemsDivider: ', ', // Divider between items in readable list
    labelExceptBefore: ' (except ', // Text before exceptions in readable list
    labelExceptAfter: ')', // Text after exceptions in readable list
    labelExceptBetween: ')', // Text between exceptions in readable list
    labelNothingIsSelected: ')', // Option for substitution of "Nothing is selected" text
    onChange: function (items, except) { // This function will be called when user is interacting with checkboxes
        console.log(items); // First parameter is list of checked items
        console.log(except); // Second parameter is list of exceptions
    }
});

Plugin is using data-id and data-name attributes in checkboxes. They are not necessary; if not set โ€” would be generated.

data-name is value that will display in readable list when corresponding checkbox is set positive (should be the same as text near checkbox). data-id is what will be passed as array item into callback function onChange.

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.