I watched the various conversations on the subject, sorry to redo a topic but I look for a whole day and I do not understand why Dropzone is not defined.
In my console it's always the same speech ... Uncaught ReferenceError: Dropzone is not defined
Where could I have been wrong?
<div action="{{path('document_create')}}" class="dropzone">
<div class="fallback">
{{ form_widget(form.file, {
'attr': {'type': 'file', 'name': 'file'}
}) }}
</div>
</div>
JS:
Dropzone.autoDiscover = false;
$(function() {
//Dropzone class
var myDropzone = new Dropzone(".dropzone", {
url: "upload.php",
paramName: "file",
maxFilesize: 2,
maxFiles: 10,
acceptedFiles: "image/*,application/pdf"
});
$('#startUpload').click(function(){
myDropzone.processQueue();
});
});
I post the solution I just found after a battle on symfony and webpack!
The trick: (for Symfony and webpack)
1 / Install dropzone
2 / Leave the file dropzone.js or dropzone.min.js in the node_modules, do not touch them.
3 / Create a file.js, ex: myDropzone.js
4 / Call Dropzone in myDropzone.js with:
window.Dropzone = require('dropzone/dist/min/dropzone.min');
5 / As well as the dropzone config code according to your choices:
Dropzone.autoDiscover = false;
$(function() {
//Dropzone class
$('.dropzone').dropzone({
paramName: "file",
maxFilesize: 2,
maxFiles: 2,
addRemoveLinks: true,
acceptedFiles: "image/*,application/pdf"
});
});