Search code examples
javascriptdropzone.jsdropzone

How to manually trigger click for Dropzone (open select file dialog)


Dropzone only works on the element itself i have an SPAN tag inside my button, and when i click on the text it won't trigger click on parent element which dropzone is attached to. i tried the following but it doesn't work!

$('.dropzone').click();

and also this

$('.dropzone').trigger('click');

Solution

  • by default dropzone only works on on element it self, and if you try to run trigger manually it wont work. the best way i could find after searching A LOT was this:

    myDropzone.hiddenFileInput.click()
    

    to find dropzone instant there are several ways:

    1- by jquery: var myDropZone = $('.dropzone').get(0).dropzone; or var myDropZone = $("div#dropmehere").dropzone({...}); if you are using id to find your element

    2- by Dropzone class itself: var myDropzone = Dropzone.forElement("div#dropmehere");

    now you can