🔬
Selectable
  • Selectable
  • Getting Started
    • Install
    • Set Up
    • States
    • Items
    • Demos
      • Checkboxes
      • Dropzone Integration
      • Sortable Integration
  • API
    • Options
      • appendTo (deprecated)
      • autoRefresh
      • autoScroll
      • classes
      • container
      • filter
      • handle
      • ignore
      • lasso
      • lassoSelect
      • maxSelectable
      • saveState
      • throttle
      • toggle
      • tolerance
      • touch
    • Properties
    • Methods
      • add()
      • attachEvents()
      • clear()
      • deselect()
      • destroy()
      • detachEvents()
      • disable()
      • enable()
      • getItems()
      • getNodes()
      • getSelectedItems()
      • getUnSelectedItems()
      • getSelectedNodes()
      • getUnSelectedNodes()
      • getFirstSelectedItem()
      • getFirstSelectedNode()
      • init()
      • invert()
      • off()
      • on()
      • once()
      • redo()
      • refresh()
      • remove()
      • select()
      • selectAll()
      • setContainer()
      • state()
      • toggle()
      • undo()
      • update()
    • Events
      • init
      • destroyed
      • start
      • drag
      • end
      • select
      • deselect
      • selecting
      • deselecting
      • add
      • remove
      • update
      • state
      • enabled
      • disabled
Powered by GitBook
On this page
  1. Getting Started
  2. Demos

Checkboxes

const SELECTABLE = new Selectable({
    filter: ".item",
    ignore: "input",
    appendTo: "#items",
    toggle: true
});

const inputs = [...document.querySelectorAll("input")];

// iterate over the inputs
for ( const input of inputs ) {
    const item = input.closest(".item");
    
    // trigger selection / deselection on checkbox change
    input.onchange = e => {
        input.checked ? SELECTABLE.select(item) : SELECTABLE.deselect(item);
    }
    
    // select items already checked
    if ( input.checked ) {
        SELECTABLE.select(item);
    }
}

// check the checkbox when item is selected
SELECTABLE.on("select", (item) => {
    item.node.querySelector("input").checked = true;
});

// uncheck the checkbox when item is deselected
SELECTABLE.on("deselect", (item) => {
    item.node.querySelector("input").checked = false;
});

PreviousDemosNextDropzone Integration

Last updated 1 year ago