Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check if Dropzone is already attached

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

like image 710
Manic Depression Avatar asked Nov 01 '16 12:11

Manic Depression


1 Answers

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();
        }
    });
}
like image 57
Filipe Baumeister Avatar answered Oct 17 '22 03:10

Filipe Baumeister