I’m trying to add an id attribute to each file uploaded in Dropzone.js, So I can sort it later on.
This is my code:
JavaScript
x
11
11
1
Dropzone.options.pictureDropzone = {
2
paramName: "file",
3
addRemoveLinks: true,
4
init: function() {
5
this.on("success", function(file, response) {
6
file.serverId = response.id;
7
$(file.previewTemplate).find('.dz-preview').attr('id', "document-" + file.serverId);
8
});
9
}
10
};
11
The line
JavaScript
1
2
1
$(file.previewTemplate).find('.dz-preview').attr('id', "document-" + file.serverId);
2
Should add the id, but it does nothing.
Tried it with prop() too.
If I choose a different element, it does work fine. for example, this works for .dz-details
JavaScript
1
2
1
$(file.previewTemplate).find('.dz-details').attr('id', "document-" + file.serverId);
2
But I cannot seem to find a way to add it to the dz-preview element.
The HTML structure looks like that:
JavaScript
1
6
1
<div class="dz-preview dz-processing dz-image-preview dz-success">
2
<div class="dz-details"> </div>
3
<div class="dz-progress"> </div>
4
<div class="dz-success-mark"> </div>
5
</div>
6
Thank you for the help 🙂
Advertisement
Answer
JavaScript
1
5
1
this.on("success", function(file, response) {
2
file.serverId = response.id;
3
$(".dz-preview:last-child").attr('id', "document-" + file.serverId);
4
});
5