I want to know how to make custom preview template. The documentation doesn't explain everything well, And I searched for tutorial about I didn't find anything.
Update
My html
<div id="dropzone">
<div id="template-preview">
<img src="assets/images/icons/plus-icon-white.png" alt="" />
<span>Choose or drop file from your computer</span>
<div class="dz-preview dz-file-preview well" id="dz-preview-template">
<div class="dz-details">
<div class="dz-filename"><span data-dz-name></span></div>
<div class="dz-size" data-dz-size></div>
</div>
<div class="dz-progress"><span class="dz-upload" data-dz-uploadprogress></span></div>
<div class="dz-success-mark"><span></span></div>
<div class="dz-error-mark"><span></span></div>
<div class="dz-error-message"><span data-dz-errormessage></span></div>
</div>
</div>
</div>
My js
var drop = $('#dz-preview-template').html();
$('#dropzone').dropzone({
url: "/upload",
maxFilesize: 100,
paramName: "uploadfile",
maxThumbnailFilesize: 5,
previewTemplate: drop,
previewsContainer: "#template-preview"
});
Drag and drop file uploads with image previews powered by Dropzone.js. You can pass any options supported by the plugin via the data-options attribute. The value must be a valid JSON object. Copy-paste the stylesheet <link> into your <head> to load the CSS.
One main goal when creating Dropzone was to have file previews that are not only practical, but also look good. That's why the default design of Dropzone looks great without you needing to do anything.
Component customization props, including the strings and object literals in the custom styles props, can also be passed as functions that react to the state of the dropzone. If, for example, you pass a func instead of a node for inputContent, this function receives (files, extra), and should return the node to be rendered.
For me it worked with
previewTemplate: document.getElementById('preview-template').innerHTML
but I think it should be the same as using html()
function in jQuery
.
The only thing I did differentially from your code, was to set autodiscover to false before. Maybe this helps you, too?
Dropzone.autoDiscover = false;
var uploadLogo = new Dropzone("div#uploadLogo", {
url: "../uploads/logo"
, method: "post"
,...
,previewTemplate: document.getElementById('preview-template').innerHTML
,...
});
UPDATE
Now I think, I know what is wrong in your code.
You have put the code for the template inside the dropzone
div. Put it outside. Then it should work.
<div id="dropzone"></div>
<div id="template-preview">
<div class="dz-preview dz-file-preview well" id="dz-preview-template">
<div class="dz-details">
<div class="dz-filename"><span data-dz-name></span></div>
<div class="dz-size" data-dz-size></div>
</div>
<div class="dz-progress"><span class="dz-upload" data-dz-uploadprogress></span></div>
<div class="dz-success-mark"><span></span></div>
<div class="dz-error-mark"><span></span></div>
<div class="dz-error-message"><span data-dz-errormessage></span></div>
</div>
</div>
The text to display for your dropzone area, you can set during initializing the dropzone:
$('#dropzone').dropzone({
...
, dictDefaultMessage: "Choose or drop file from your computer"
For dropzone.js version 5.5.0
you simply create a div with the id tpl
then put the template inside it.
When you define dropzone just set it like this:
var myDropzone = new Dropzone(
"div#div_submit",
{
url: "mypage.aspx",
previewTemplate : document.querySelector('#tpl').innerHTML
}
);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With