Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

removing all manually added files from Dropzone.js?

There is a unknown problem while programmatically deleting programmatically added files to Dropzone. Here is my code that is not working:

// constructor - OK
docsDropzone = new Dropzone( "#docsUpload", {
    url: uploadUrl,
    addRemoveLinks: true,
    init: function() {
        this.on( 'removedfile', removedFileCallback );
    }
} );

// add file - OK
var mockFile = { name: 'test.jpg', size: 0 };
docsDropzone.emit( "addedfile", mockFile );
docsDropzone.emit( "thumbnail", mockFile, 'test.jpg' );

// remove files - NOT OK
docsDropzone.removeAllFiles( true );
like image 262
AMIB Avatar asked Feb 19 '14 08:02

AMIB


People also ask

How do I remove all files from dropzone?

dropzone has the following function for removing all files. If you want to remove all files, simply use . removeAllFiles().

How do I remove photos from dropzone?

If you want to remove an added file from the dropzone, you can call . removeFile(file) . This method also triggers the removedfile event. myDropzone.

How does dropzone JS work?

Dropzone. js is 'a light weight JavaScript library that turns an HTML element into a "dropzone"'. Users can drag and drop a file onto an area of the page, uploading to a server. If you would like to read more how all of this works skim through the Dropzone.


1 Answers

addedfile function is not adding files to dropzone.files so it must be added manually:

// add file - OK
var mockFile = { name: 'test.jpg', size: 0, status: 'success' };
docsDropzone.emit( "addedfile", mockFile );
docsDropzone.emit( "thumbnail", mockFile, 'test.jpg' );
docsDropzone.files.push( mockFile ); // file must be added manually

// remove files - NOW OK
docsDropzone.removeAllFiles( true );
like image 149
AMIB Avatar answered Nov 01 '22 04:11

AMIB