ncuesta / dropzonejs-rails

Spice your Rails apps with some Dropzone sugar!
http://rubygems.org/gems/dropzonejs-rails
MIT License
312 stars 56 forks source link

Two dropzones on one page? #40

Closed gbrl closed 7 years ago

gbrl commented 7 years ago

I'm trying to put two dropzones on one page, and it seems to be causing issues. I get this error:

Uncaught Error: Dropzone already attached.

Here is my code:

document.addEventListener("turbolinks:load", function() {

  if($('form.app_cv').length > 0) {
    var firstDropzone = new Dropzone(".app_cv");
    firstDropzone.options.new_upload = { maxFilesize: 1 }
    firstDropzone.on("complete", function(file) {
      window.location.reload();
    });
  }

  if($('form.generic').length > 0) {
    var genericDropzone = new Dropzone(".generic");
    genericDropzone.options.new_upload = { maxFilesize: 1 }
    genericDropzone.on("complete", function(file) {
      window.location.reload();
    });
  }

});

Also, the window.reload command executes only on the second dropzone, not the first. Any ideas? Thanks for your time!!!

ncuesta commented 7 years ago

Hi! Can you please provide some more context to the problem? The relevant HTML code, for instance.

Thanks,

Nahuel Cuesta Luengo @ncuestal · nahuelcuestaluengo@gmail.com

On Nov 20, 2016, 19:07 -0300, Gabriel Rambert notifications@github.com, wrote:

I'm trying to put two dropzones on one page, and it seems to be causing issues. I get this error:

Uncaught Error: Dropzone already attached.

Here is my code:

document.addEventListener("turbolinks:load", function() { if($('form.app_cv').length > 0) { var firstDropzone = new Dropzone(".app_cv"); firstDropzone.options.new_upload = { maxFilesize: 1 } firstDropzone.on("complete", function(file) { window.location.reload(); }); } if($('form.generic').length > 0) { var genericDropzone = new Dropzone(".generic"); genericDropzone.options.new_upload = { maxFilesize: 1 } genericDropzone.on("complete", function(file) { window.location.reload(); }); } });

Also, the window.reload command executes only on the second dropzone, not the first.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub (https://github.com/ncuesta/dropzonejs-rails/issues/40), or mute the thread (https://github.com/notifications/unsubscribe-auth/AAF1aBTMbF6EByPKo3RSWVWk_3Jh7i0cks5rAMSggaJpZM4K3rEY).

ncuesta commented 7 years ago

Closing this for inactivity.