Vue-js-modal not displaying Dropzone.js

I'm currently working on a project that involves using both the vue-js-modal plugin by euvl and dropzone.js for handling multiple file uploads.

My goal is to integrate both libraries so that users can open a modal window and upload files. However, I've encountered an issue where the dropzone.js library seems to not be properly initialized. The modal opens up, but the dropzone container fails to allow photo uploads.

Despite checking the console for errors, I haven't been able to pinpoint the root cause of the problem. Neither the file upload window appears nor can files be dragged and dropped into the container.

Below is a snippet of my Vue component code:

<template>
<modal name="upload-files-modal" classes="p-4 bg-card rounded-lg" height="auto">
        <div class="card mt-3">
        <h3 class="font-normal text-xl py-4 -ml-5 mb-3 border-l-4 border-blue-light pl-4">
           Upload some pictures
        </h3>
            <form id="newForm" method="POST" action="" class="dropzone" >
            </form>
        </div>
</modal>
</template>

<script>
import Dropzone from 'dropzone'
import 'dropzone/dist/dropzone.css'

Dropzone.autoDiscover = false;
Dropzone.options.newForm = {
        paramName: 'photo',
        maxFilesize: 3,
        acceptedFiles: '.jpg, .jpeg, .png .bmp',
        init: function () {
        // Set up any event handlers
        this.on('queuecomplete', function (file) {
                location.reload();
        });
    }
}

export default {
    props: ['uploadurl']
}
</script>

In my Laravel blade file, here is how I implement the Vue component:

<upload-files-modal uploadurl="{{ $project->path() . '/photos' }}" ></upload-files-modal>

<a href="" @click.prevent=$modal.show('upload-files-modal')>Upload Photo</a>

Answer №1

It is advisable to initialize the Dropzone only after the modal has been opened.

For instance

Dropzone.autoDiscover = false;

const VModal = window["vue-js-modal"].default;

Vue.use(VModal)

const dropForm = Vue.component('drop-form', {

  template: `<div class="content">
  <modal name="modal" @opened="afterOpen">
    <div ref="dropZoneRef" class="dropzone"></div>
  </modal>
  <button @click="showModal()">Upload files</button></div>`,
  methods: {
    showModal() {
      this.$modal.show('modal')
    },
    afterOpen() {
      const dropZone = new Dropzone(this.$refs.dropZoneRef, {
        url: "/file/post"
      });
    }
  },
  mounted() {
  }
});

new Vue({
  el: '#root',
  template: `<drop-form></drop-form>`
})
.content {
  padding: 1rem;
  border: 1px solid black;
  height: 200px;
}

#dropZone {
  height: 100px
}
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/dropzone/5.7.0/basic.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/dropzone/5.7.0/dropzone.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/dropzone/5.7.0/dropzone.js"></script>
<script src="https://unpkg.com/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="5f292a3a72352c7232303b3e331f6d716f716f722d3c716c">[email protected]</a>/dist/index.js"></script>
<div id="root"></div>

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

Is it possible to avoid passing each individual Vue prop by destructuring them?

Essentially, I am working with a component <Device> v-for="device in devices" :key="device.name" :device="device" :name="device.name" :number="device.number" :type="device.type" :status=&qu ...

Synchronous loading of script that dynamically works across various browsers

Looking for a solution to dynamically load a JS file synchronously. I considered using an XHR request for the script (specifically CDN dojo), however, I encountered the cross domain origin policy issue. Any advice or suggestions would be greatly appreciat ...

Issue with Caching during Javascript Minification

I Have ASP.Net MVC 3 App. Utilizing YUICompressor.Net for compressing Javascript and CSS files post build with MSBuild. The minimized javascript file is named JSMin.js and the CSS file is CssMin.css. In my master page, I reference these files as shown bel ...

Troubleshooting problems with the guildMemberAdd event handler

As I continue on my journey with discord.js v12, I've encountered yet another issue with an event handler. While most events have been working fine so far, such as message or ready, I am currently facing a challenge with guildMemberAdd event. My goal ...

The File Reader just informed me that parameter 1 is not in the form of a blob

When working with a file input in my React component, I keep encountering an error with the FileReader. Here's the specific error message: Uncaught TypeError: Failed to execute 'readAsDataURL' on 'FileReader': parameter 1 is not o ...

Graphql query using $http.post is unsuccessful

I successfully made a request for the code below, but I am encountering an issue where I am not receiving any data back. The "preview" tab of the request in Chrome simply displays "Error Not Found". Interestingly, when I try the same query in GraphiQL, i ...

Tips for removing arrays and their values when a duplicate id is detected

Is there a way to remove or filter out subsequent arrays and their values if a duplicate id is found in the previous array? For instance: const a1 = ["id1", "b", "c", "d", "e"], a2 = ["id2", ...

Using MVC4 and jQuery to unselect items from an Html.CheckboxListFor

In my search page, I am utilizing jQuery to toggle the visibility of different sections based on user input. Specifically, I have a Html.Textbox and Html.CheckboxListFor that are shown or hidden depending on whether there is any input in the textbox or if ...

When utilizing a computed property that accesses the Vuex state, the v-if directive alone may not function as expected without

Uncertain of the source of the issue, but the basic v-if functionality seems to be malfunctioning. <template> <div> <select v-model="col.code"> <option v-for="i in foo" :value="i.code" ...

Getting the position (x y coordinates) of moving elements in React Beautiful DND: A step-by-step guide

My question is related to React Beautiful DND - Is there a way to obtain the position (X Y) of objects that are being dragged on the screen? Any suggestions or solutions would be greatly appreciated. Thank you! ...

What is the best way to create an array within an object during the parsing process

When working with a JSON object, I need to assign a value stored in the session against an ID. The JSON data is as follows: [ { "id": "a", "text": "a", "icon": true, "li_attr": { "id": "a" }, "a_attr": { "href": "#" ...

Uncover the secrets of HTML with JavaScript

I'm facing an issue with extracting data from a link's data attribute and trying to decode the HTML within it, but unfortunately, it's not functioning as expected. Check out my code on JSFiddle: http://jsfiddle.net/Kd25m/1/ Here's the ...

Endless surfing just like Bing

I'm on the lookout for a library that can enable continuous scrolling in jQuery and/or JSP, similar to the functionality seen in Bing Images. Specifically, I want the feature where only the results within the visible area are loaded when users scroll ...

Is there a way to determine the precise location of the scrollbar within a div element?

Is there a way to obtain the exact position of the scrollbar (scrollY) for a specific div, rather than the entire window? I found an example that seems similar to what I need at the following link: http://plnkr.co/edit/45gKhAIt0DrozS7f0Bz2?p=preview Ho ...

Conceal descendant of list item and reveal upon clicking

In my responsive side menu, there is a submenu structured like this: .navbar ul li ul I would like the child menus to be hidden and only shown when the parent menu is clicked. Although I attempted to achieve this with the following code, it was unsucces ...

Decode the string containing indices inside square brackets and transform it into a JSON array

I have a collection of strings that contain numbers in brackets like "[4]Motherboard, [25]RAM". Is there a way to convert this string into a JSON array while preserving both the IDs and values? The desired output should look like: {"data":[ {"id":"4","i ...

Converting PHP variables to JavaScript using AJAX and XML communication

In order to gain a deeper understanding, I am determined to tackle this task without relying on jQuery. This means I am willing to reinvent the wheel in order to fully comprehend how it functions. My research has led me to believe that AJAX is the key to a ...

Methods for removing cookie during logout with Express and Passport JS?

I have been struggling to delete cookies upon logout but haven't had any luck so far. I searched online and came across two methods: Setting a new expiration date for the cookie res.cookie('connect.sid', '', {expires: new Date(1 ...

Using the max-width property with Semantic UI Dropdown in ReactJS

I'm struggling to determine how to adjust the max-width of the Dropdown element in ReactJS. I attempted the following: .Menu Dropdown { max-width: 5rem !important; } Unfortunately, this did not work as expected. The dropdowns are taking up too m ...

"Automate the process of manual content duplication with JavaScript's for each replacement

Seeking a solution to automate the selection process without writing individual JS scripts for every input. For instance, having 10 double inputs (total of 20 inputs) and utilizing the each() function or other methods by only declaring selectors. Find th ...