A JavaScript library for creating "select-all" checkboxes

Overview

SelectAllCheckbox v1.0

See LICENSE for this software's licensing terms.

SelectAllCheckbox is a JavaScript library which makes it easy to create "select all" checkboxes for checkbox groups.

This library is a vanilla JavaScript port of my jQuery SelectAllCheckbox plugin.

Differences between this and the jQuery version

  • This library is incompatible with all versions of IE. I do projects like this to learn, and I wanted to use ES6 features. (I tested in Chromium, Firefox and legacy Edge, and those were OK).
  • The use of indeterminate checkboxes can no longer be disabled via configuration
  • Minor API differences, though conceptually it's the same (see the Using section)

Features

  • Grants a checkbox control over a group of checkboxes to select or deselect all of them
  • When checkboxes are individually checked/unchecked, the select-all checkbox's state updates accordingly between not checked, indeterminate (partially checked) and checked
  • Supports any number of checkbox groups
  • Configuration accepts a callback which executes when one or more checkboxes changes state
  • The callback receives the changed checkbox(es) as an array of DOM objects, plus the status of the checkbox group (all/some/none checked)
  • Select-all checkboxes do not modify the state of disabled checkboxes. Disabled checkboxes do affect the state of the select-all checkbox.

Using

Class: CheckboxGroup

Class Constants

Property Description
CheckboxGroup.GROUP_STATE_NONE Reflects the state of the checkbox group; a string with value none
CheckboxGroup.GROUP_STATE_SOME Reflects the state of the checkbox group; a string with value some
CheckboxGroup.GROUP_STATE_ALL Reflects the state of the checkbox group; a string with value all

Constructor Arguments

Property Description
selectAllId The HTML "id" attribute of the select-all checkbox
groupName The HTML "name" attribute of the checkboxes. Note: the select-all checkbox should not have a "name" attribute.
onChangeCallback A callback to execute when a checkbox's state changes

The callback function receives two arguments:

  1. The affected checkboxes as an array of DOM objects
  2. A string representing how many checkboxes in the group are checked; see CheckboxGroup.GROUP_STATE_NONE, CheckboxGroup.GROUP_STATE_SOME and CheckboxGroup.GROUP_STATE_ALL.

Example

let group1 = new CheckboxGroup(
   "selectAllButton",
   "checkboxGroup",
   function( checkboxes, checkedState ) { do stuff; }
);

See demo/demo.html file for a more thorough demo.

If you change a checkbox's state via script (for example, with document.getElementById("box1").checked = true, you must manually fire the change event on the checkbox to ensure that the select-all checkbox's state is updated.

You might also like...

Flexible JavaScript library for creating squircley magic ✨

Flexible JavaScript library for creating squircley magic ✨

squircley.js squircley.js is the core squirclular magic ✨ from https://squircley.app wrapped up into a simple, 0 dependency JavaScript library. squirc

Dec 24, 2022

A dependency-free JavaScript library for creating discreet pop-up notifications.

Polipop A dependency-free JavaScript library for creating discreet pop-up notifications. Demo See demo at minitek.github.io/polipop/. Documentation Se

Aug 15, 2022

A simple easy to use vanilla JavaScript library for creating input fields that accept multiple email addresses

MeiMei - Multiple Email Input MeiMei: A simple easy to use vanilla JavaScript library for creating input fields that accept multiple email addresses.

Apr 13, 2022

A lightweight JavaScript library for creating snackbar & toaster notifications.

Notify.js Notify.js is a lightweight (2.3kb) utility library for creating snackbar and toaster notifications. Installation Download Notify.js via NPM:

Feb 13, 2022

jQuery Terminal Emulator - JavaScript library for creating web-based terminals with custom commands

jQuery Terminal Emulator - JavaScript library for creating web-based terminals with custom commands

JavaScript Library for Web Based Terminal Emulators Summary jQuery Terminal Emulator is a plugin for creating command line interpreters in your applic

Jan 1, 2023

Atomico a micro-library for creating webcomponents using only functions, hooks and virtual-dom.

Atomico a micro-library for creating webcomponents using only functions, hooks and virtual-dom.

Atomico simplifies learning, workflow and maintenance when creating webcomponents. Scalable and reusable interfaces: with Atomico the code is simpler

Dec 31, 2022

The PatternFly Design Kit is a Sketch library used for creating PatternFly accurate design mockups

PatternFly Design Kit The PatternFly Design Kit is a collection of Sketch assets that make it easy for designers to create high-fidelity design mockup

Jan 2, 2023

An open-source library to help with creating expandable text

🔭 Telescopic Text An open-source library to help with creating expandable text. Inspired by StretchText and TelescopicText. I've been thinking a lot

Dec 30, 2022

Library for creating corrupted calldata.

Scuffed ABI Package for modifying ABI encoded data. Mostly useful for testing failure cases of ABI decoders. Given an ethers Contract object, you can

Nov 29, 2022
Owner
Kurtis LoVerde
Kurtis LoVerde
Hemsida för personer i Sverige som kan och vill erbjuda boende till människor på flykt

Getting Started with Create React App This project was bootstrapped with Create React App. Available Scripts In the project directory, you can run: np

null 4 May 3, 2022
Kurs-repo för kursen Webbserver och Databaser

Webbserver och databaser This repository is meant for CME students to access exercises and codealongs that happen throughout the course. I hope you wi

null 14 Jan 3, 2023
Fancytree - JavaScript tree view / tree grid plugin with support for keyboard, inline editing, filtering, checkboxes, drag'n'drop, and lazy loading

Fancytree Fancytree (sequel of DynaTree 1.x) is a JavaScript tree view / tree grid plugin with support for keyboard, inline editing, filtering, checkb

Martin Wendt 2.6k Jan 9, 2023
iOS 7 style switches for your checkboxes

Description Switchery is a simple component that helps you turn your default HTML checkbox inputs into beautiful iOS 7 style switches in just few simp

Alexander Petkov 2.1k Dec 31, 2022
Highly customizable checkboxes and radio buttons (jQuery & Zepto)

iCheck plugin 1.0.3 Highly customizable checkboxes and radio buttons for jQuery and Zepto. Refer to the iCheck website for examples. Note: iCheck v2.0

Dar Gullin 7.4k Dec 25, 2022
Converts select multiple elements into dropdown menus with checkboxes

jquery-multi-select Converts <select multiple> elements into dropdown menus with a checkbox for each <option>. The original <select> element is hidden

mySociety 22 Dec 8, 2022
Highly customizable checkboxes and radio buttons (jQuery & Zepto)

iCheck plugin 1.0.3 Highly customizable checkboxes and radio buttons for jQuery and Zepto. Refer to the iCheck website for examples. Note: iCheck v2.0

Dar Gullin 7.5k Aug 24, 2022
A pure CSS toggle switch for form input checkboxes

Toggle Switchy A pure CSS toggle switch for form input checkboxes Preview Installation CSS <link rel="stylesheet" href="toggle-switchy.css"> HTML <lab

Adam Culpepper 34 Dec 8, 2022
JavaScript library for creating dynamic content

Gruu Gruu is a small and powerful JavaScript library for creating dynamic content. Using only JavaScript you can create user interfaces that change dy

Marek Łabuz 7 Jun 25, 2021
A lightweight JavaScript library for creating interactive maps and pretty data visualization.

Jsvectormap A lightweight Javascript library for creating interactive maps and pretty data visualization. Explore docs . Report bug · View demo · Down

Mustafa Omar 204 Dec 24, 2022