Check if Dropzone is already attached
Asked Answered
L

1

5

There are few dropzones on a page and new items are loaded by ajax, so I need to check, if dropzone already attached on that item.

    Dropzone.autoDiscover = false;


    function initDropzones()
    {

        $('.dropzones').each(function () {

            // how to check dropzone exists on item?
            // or how to destroy already existed dropzone (so reinitialize after)

            $(this).dropzone({
                url: ...
            })
        });
    }

    someAjaxAdd() {
        // add new elements and with new one dropzone
        initDropzones();
    }

Thank you very much

Lozano answered 1/11, 2016 at 12:9 Comment(4)
I solve it with try catch, but I will be glad if someone offer better solutionLozano
You want to know if there is files in your dropzone ?Trellis
No, I want to know if dropzone is initialized on the element. Sorry for bad formulationLozano
Have you seen this init function in the doc ? dropzonejs.com/#config-initTrellis
D
13

You have to check the dropzone attribute and if it exists you can destroy it:

function initDropzones() {
    $('.dropzone').each(function () {

        let dropzoneControl = $(this)[0].dropzone;
        if (dropzoneControl) {
            dropzoneControl.destroy();
        }
    });
}
Derive answered 12/10, 2017 at 16:6 Comment(1)
you can check like dropzoneControl == undefinedBrandt

© 2022 - 2024 — McMap. All rights reserved.