🔬
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
  • Listening for an event once
  • Event reference
  1. API

Events

Previousupdate()Nextinit

Last updated 1 year ago

Selectable fires a number of custom events that the instance can listen for.

You can attach a number of custom event listeners using the method and pass the event name and a callback as the first two arguments:

const selectable = new Selectable();

selectable.on('event_name', myCallback);

Event listeners can be detached by calling the method with the same arguments:

selectable.off('event_name', myCallback);

Both the on() and off() methods function the same as the native and methods respectively.

This means that in order to remove a custom event listener from the instance, you must pass the same to the off() method as you did to the on() method - cannot be removed.

Incorrect

selectable.on('end', function(e, selected, unselected) {
    counter.value = selected.length;
});

Correct

const myCallback = function(e, selected, unselected) {
    counter.value = selected.length;
};

// add the event listener
selectable.on('end', myCallback);

// remove the event listener
selectable.off('end', myCallback);

Listening for an event once

const myCallback = function(e, selected, unselected) {
    // Do something once

    // Remove the event listener
    this.off('select', myCallback);
};

// Add the event listener
selectable.on('select', myCallback);

Event reference

Name
Description

The instance is ready.

The instance has been destroyed

An item was added to the instance.

An item was removed from the instance.

mousedown / touchstart.

mousemove / touchmove.

mouseup / touchend.

An item was selected.

An item was deselected.

An item has been marked for selection.

An item has been marked for deselection.

Save state change.

The instance was enabled.

The instance was disabled.

on()
off()
addEventListener
removeEventListener
function expression
declared / anonymous functions
init
destroyed
add
remove
start
drag
end
select
deselect
selecting
deselecting
state
enabled
disabled