🔬
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

Dropzone Integration

/* --------- DROPZONE INSTANCE --------- */
const DROPZONE = new Dropzone("#dropzone", {
    autoProcessQueue: false,
    clickable: '#addFiles',
});

/* --------- SELECTABLE INSTANCE --------- */
const SELECTABLE = new Selectable({
    appendTo: "#dropzone",
    ignore: "[data-dz-remove]", // stop remove button triggering selection
});

/* --------- SELECTABLE EVENTS --------- */
SELECTABLE.on("end", (e, selected) => {
    // show the "removeFiles" button if we have selected files
    removeFiles.classList.toggle("active", selected.length);
});

/* --------- DROPZONE EVENTS --------- */
DROPZONE.on("addedfile", function(file) {
    const el = file.previewElement;
    
    // add element to Selectable instance when added by Dropzone
    SELECTABLE.add(el);	
});

DROPZONE.on("removedfile", function(file) {
    const el = file.previewElement;
    
    // remove element from Selectable instance when removed by Dropzone
    SELECTABLE.remove(el);
});

/* --------- BUTTONS --------- */
const removeFiles = document.getElementById("removeFiles");

removeFiles.addEventListener("click", e => {
    // get files
    const files = DROPZONE.files;
    
    if ( files.length ) {
        for ( const file of files ) {
            // get the item instance from Selectable
            const el = SELECTABLE.get(file.previewElement);
            
            // if it's selected, then remove it.
            // Dropzone is set to listen to "removedfile" and 
            // will remove it from the Selectable instance
            if ( el.selected ) {
                DROPZONE.removeFile(file);
                
                // hide the button
                removeFiles.classList.remove("active");
            }
        }
    }
});    

PreviousCheckboxesNextSortable Integration

Last updated 1 year ago