"Troubleshooting: The Dropzone js code sample from the documentation

I am currently implementing a tutorial from the documentation provided by Dropzone.js. However, I seem to be encountering an issue as the example is not working correctly. Here is the structure that I currently have:

Dropzone.options.myAwesomeDropzone = { // The camelized version of the ID of the form element

  // The configuration we've talked about above
  autoProcessQueue: false,
  uploadMultiple: true,
  parallelUploads: 100,
  maxFiles: 100,

  // The setting up of the dropzone
  init: function() {
    var myDropzone = this;

    // First change the button to actually tell Dropzone to process the queue.
    this.element.querySelector("button[type=submit]").addEventListener("click", function(e) {
      // Make sure that the form isn't actually being sent.
      e.preventDefault();
      e.stopPropagation();
      myDropzone.processQueue();
    });

    // Listen to the sendingmultiple event. In this case, it's the sendingmultiple event instead
    // of the sending event because uploadMultiple is set to true.
    this.on("sendingmultiple", function() {
      // Gets triggered when the form is actually being sent.
      // Hide the success button or the complete form.
    });
    this.on("successmultiple", function(files, response) {
      // Gets triggered when the files have successfully been sent.
      // Redirect user or notify of success.
    });
    this.on("errormultiple", function(files, response) {
      // Gets triggered when there was an error sending the files.
      // Maybe show form again, and notify user of error
    });
  }

}
<head>
  <meta charset="UTF-8">
  <title>Dropzone JS tutorial</title>
  <script src="https://unpkg.com/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="7c180e130c061312193c4a524c524c511e19081d524d">[email protected]</a>/dist/dropzone-min.js"></script>
  <link href="https://unpkg.com/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="f89c8a97888297969db8ced6c8d6c8d59a9d8c99d6c9">[email protected]</a>/dist/dropzone.css" rel="stylesheet" type="text/css" />

</head>

<body>
  <form id="my-awesome-dropzone" class="dropzone" action="#">
    <div class="dropzone-previews"></div>
    <!-- this is where the previews should be displayed -->

    <!-- Now set up your input fields -->
    <input type="email" name="username" />
    <input type="password" name="password" />

    <button type="submit">Submit data and files!</button>
  </form>
<script src="dropzone-custom.js"></script>
</body>

This is the output that I am seeing: https://i.sstatic.net/bZIYs.png

Upon checking the debug console, I am unable to locate any errors. Can anyone provide insight on what might be missing or what mistake I could potentially be making?

Answer №1

It is essential to utilize

Dropzone.find();

prior to configuring your settings since auto Discovery no longer exists in version 6. Thus, your setup should include:

Dropzone.discover();
Dropzone.options.myAmazingCustomDropZone = { 

}

Answer №2

Upon closer inspection, it appears that the issue with the mentioned example stems from how values are passed to Dropzone. Utilizing the constructor method seems to resolve this issue.

const dz = new Dropzone(".dropzone", {

  // The configuration we've discussed earlier
  autoProcessQueue: false,
  uploadMultiple: true,
  parallelUploads: 100,
  maxFiles: 100,

  // Setting up the dropzone
  init: function() {
    var myDropzone = this;

    // Modify the button to instruct Dropzone to process the queue.
    this.element.querySelector("button[type=submit]").addEventListener("click", function(e) {
      // Prevent the default form submission.
      e.preventDefault();
      e.stopPropagation();
      myDropzone.processQueue();
    });

    // Listen for the sendingmultiple event instead of sending when uploadMultiple is set to true.
    this.on("sendingmultiple", function() {
      // Triggered when the form is being sent.
      // Hide success buttons or completion forms.
    });
    this.on("successmultiple", function(files, response) {
      // Triggered upon successful file submission.
      // Redirect user or notify success.
    });
    this.on("errormultiple", function(files, response) {
      // Triggered if there was an error in file submission.
      // Possibly display form again and inform user of the error.
    });
  }

});
<head>
  <meta charset="UTF-8">
  <title>Dropzone JS tutorial</title>
  <script src="https://unpkg.com/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="4a2e38255a5143444f6a7c647a647a67282f3e2b647b">[email protected]</a>/dist/dropzone-min.js"></script>
  <link href="https://unpkg.com/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="2c485e435c564342496c6a7c647a647a6279497868040f30d0401705f0e151a7376717c7775381510">[email protected]</a>/dist/dropzone.css" rel="stylesheet" type="text/css" />

</head>

<body>
  <form id="my-awesome-dropzone" class="dropzone" action="#">
    <div class="dropzone-previews"></div>
    <!-- Previews will be displayed here -->

    <!-- Input field setup -->
    <input type="email" name="username" />
    <input type="password" name="password" />

    <button type="submit">Submit data and files!</button>
  </form>
  <script src="dropzone-custom.js"></script>
</body>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The NextAuth file imported with the EmailProvider is currently not being utilized

Having an issue with implementing nextauth for authentication. I have imported EmailProvider from nextauth/providers but when I try to use it in the Nextauth providers object, it does not recognize the EmailProvider that I've imported. Here is the co ...

An option instead of using a pop-up window

Currently, I have a PHP script and a small form that allows users to upload image files. The user can access this feature by clicking on a button on the parent HTML page, which opens up a Pop Up Window. I understand that not everyone is a fan of 'Pop ...

Updating the value of a Javascript variable from a separate file

Hello there! I have a file named map.php and I need to modify the center value in the code to be based on a different value provided by another JavaScript file called template.js. In the past, I was able to change other HTML values using setAttribute and q ...

Vue js parent-child communication using event bus fails to function

Is there any way to successfully communicate between non parent child components in vue js document? I followed the instructions in the vue document, but unfortunately, my code did not work as expected. Below is a snippet of my code: The structure of the ...

Using AJAX in JavaScript within an HTML document is a valuable skill to have

I have the following JavaScript function that I need to call the /print2 function without clicking any buttons. I attempted to use Ajax for this, but I am new to Ajax and JavaScript. Can you help me identify where the issue might be? Thank you... <scr ...

Executing both JavaScript Promise .then() and .catch concurrently

I've been working on converting my WordPress comments into an ajax-driven system. Everything was going smoothly until I encountered a problem with the .catch() method triggering right after the .then() method. Below is the code snippet... Ajax engi ...

I can't seem to get anything to show up on my React

After starting to work with routing on react.JS, I encountered a challenge where the simple products.jsx file is supposed to display a simple message upon clicking, but it's not showing anything. Here is the code from Index.JS import React from &apos ...

Can you include the dollar symbol in the currency format?

I currently have this code that formats numbers into currency format, however I would like to include the dollar sign ($) before the numbers. document.getElementById("numbers").onblur = function (){ this.value = parseFloat(this.value.r ...

Using jQuery to retrieve the domain extension from a URL

Seeking assistance with extracting domain extensions from various URLs using jQuery. Uncertain how to account for all possible scenarios. Here are the parts of the URL that need to be extracted: https://www.amazon.**com**/dp/067144901X https://www.amazon. ...

Looping through required fields in jQuery based on a CSS class

Is there a way to loop through required fields marked with <input class="required">? Currently, only the first input in the loop is being evaluated. How can I traverse the DOM using a loop to check all input boxes? Thank you for your help. While I ...

Navigating through various JSON arrays using Angular

I am currently working with a large JSON file in Angular and trying to iterate through it. The structure of the JSON file is as follows: { "subject1":[ { "title":"titlehere", "info":"infohere." }], ...

Leverage the selected values to dynamically generate a table using jQuery

Can someone help me figure out how to store multiple values from a selection and then create an array using jQuery? Here's the scenario: In my multiple selection, I have 5 values: <select name="animal" id="animal" multiple="multiple">    ...

Challenges regarding variable scope in JavaScript

Presented below is the JavaScript code I am currently using, which involves jQuery: function language(language) { var text = new Object(); $.ajax({ type: "GET", url: "includes/xml/languages/" + language + ".xml", dataType: ...

The difference between `$(document)` and `$("document")` is like night

Does a distinction exist between: $(document) and $("document")? ADJUSTMENT: also when using the .ready() method like $("document").ready() ...

Looking to enhance code readability using regular expressions

While I am not a programmer, I enjoy exploring and learning new things. Here is what I have: 1) My URL is structured like this: http://site.com/#!/show/me/stuff/1-12/ 2) I have a jQuery pagination script that displays the number of available pages. Each ...

Retrieving information from a separate JavaScript file

I'm currently developing a Discord Bot and my code is all contained within one file. My goal now is to break this code up into multiple files for better organization. For instance, I plan to have: index.js which will handle all the requires (e.g. var ...

Retrieve information from the index resource using AJAX

I feel like I might be overcomplicating things, but basically, I'm trying to retrieve all the data from an index resource and have it load when a button is clicked using AJAX. I've been using a serializer to tidy up the JSON. Both "/categories" ...

Is there a way to prevent certain code from executing during server deployment?

First of all, my apologies for any mistakes in my English language skills. I find Morgan to be a great tool for development, but I am uncertain about deploying my server and not wanting everyone to see who is online. How can I prevent certain actions fro ...

Using the JQuery template with $.get function does not produce the desired result

Working on populating a table using a Jquery Template can be tricky. One challenge is incorporating a json file via an ajax call for the population process. $(document).ready(function() { var clientData; $.get("/webpro/webcad/lngetusuario", funct ...

Arranging the Bars in a Bar Chart Using Chart.JS

Lately, I've been playing around with ChartJS and encountering an issue with sorting the bars in descending order, from lowest to highest. Despite my efforts to troubleshoot, I haven't had any success in resolving it. ...