Question

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 );
Was it helpful?

Solution

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 );
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top