Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dropzone "addedfile" is not fired when adding images programatically

I want to add checkbox to dropzone images so that I can upload only the selected ones. I am going to add a checkbox next to each image when the addedfile event is fired.

I am using the following method to programmatically add images to dropzone:

var mockFile = { name: "image.jpg", size: 12345 };
imgUrl = "http://example.com/image.jpg"
myDropzone.options.addedfile.call(myDropzone, mockFile);
myDropzone.options.thumbnail.call(myDropzone, mockFile, imgUrl);

The problem is that the "addedfile" event is not fired for images added this way:

myDropzone.on("addedfile", function(file) {
    console.log("file added!"); // this line is never printed
});

But if added an image by manually clicking on dropzone and selecting a file, the above event would fire. Why is this event not fired in the first case?

like image 526
B Faley Avatar asked Sep 05 '25 03:09

B Faley


1 Answers

Don't do what I did and try to listen for the addedFile event instead of addedfile (d'oh).

like image 51
gregdev Avatar answered Sep 07 '25 21:09

gregdev