How to destroy dropdzonejs?
Asked Answered
M

5

12

How to destroy dropdzonejs?

When I have SPA and leave the page, I want to clean up so it does not listen to body events anymore.

Mayolamayon answered 29/4, 2018 at 15:29 Comment(0)
G
13
myDropzone.destroy();

I swear I had the same problem and I'll find that with a lucky attempt... it works!

Gilcrest answered 21/3, 2020 at 17:24 Comment(0)
B
2

I removed removedfile() function from Dropzone options and myDropzone.destroy(); worked for me.

Benzidine answered 20/4, 2020 at 23:41 Comment(1)
Why did you have to remove the removedfile() function from the DropZone options? I have this function, and the .destroy() or .disable() function work out-of-the-box (tested with DropZone 5.x and 6.x).Heartstricken
H
1

According to the documentation:

If you do not need a dropzone anymore, just call .disable() on the object. This will remove all event listeners on the element, and clear all file arrays. To reenable a Dropzone use .enable()

If you initialize dropzone like:

var myDropzone = new Dropzone("#mydropzoneid", { url: "/some/url"});

You should be able to disable it with:

myDropzone.disable();
Hostile answered 29/4, 2018 at 20:3 Comment(0)
H
0

Use one of the following methods : The destroy() and disable() methods both exist, and they seem to act the exact same way.

In fact, DropZone does not have a real destruction method. These methods will "put the instance in pause" (what is, by design, the closest implementation of a DropZone instance destruction).

This applies to DropZone 5.x and DropZone 6.x (try myDropzone.disable() or myDropzone.destroy() in the console on this v6.x example page https://www.dropzone.dev/bootstrap.html) : The DropZone instance will be disabled, thus leading to the "Add Files..." button being inoperative.

The instance can then be re-enabled by calling myDropzone.enable().


PS : DropZone switch from v5 to v6 in 2021-2022. The website was completely revamped and screwed-up: the documentation is partial, incomplete, too short.

If you still need to access the excellent and exhaustive v5 documentation, you can head up to the obvious Web Archive Wayback machine ! Here is the very latest v5 documentation page https://web.archive.org/web/20210829160314/https://www.dropzonejs.com/

Heartstricken answered 24/5, 2022 at 6:14 Comment(0)
G
0

If you want destroy all dropzone instances just add if (Dropzone.instances.length > 0) Dropzone.instances.forEach(dz => dz.destroy()) to document ready.

Greenish answered 19/7, 2022 at 6:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.