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

Using dropzone within a form #27

Closed sanjams2 closed 9 years ago

sanjams2 commented 9 years ago

I have searched everywhere for an answer to this problem, but no one seems to have the same issue. I am trying to add multiple a dropzone areas to a form. I am using paperclip and therefore structured my main controller to create multiple additional models with attached files. Everytime I add a dropzone class to my file_field_tag the class gets recognized, but none of dropzone javascript or styling works. However when I add the dropzone class to the class wrapper of the form, everything works, however this is not what I am going for since I have multiple other fields for the viewer to fill out.

For reference the set up is a post has many pdfs (using paperclip each pdf has one flyer)

Below is the line that I am trying to get to work, but won't

<%= file_field_tag "flyers[]", multiple: true, class: "form-control dropzone" %>

This is the line where the dropzone works, but creates it around the entire form

<%= form_for @post, :html => { :class => 'form-horizontal dropzone', multipart: true } do |f| %>

Has anyone had this problem, or know a solution. I'm beyond stuck and I have tried everying. Thanks in advance

ncuesta commented 9 years ago

Hi @jsanders67 . Thanks for posting your question here, but I think you'll be better off asking such questions at Dropzone's repo. This is a simple gem to bundle the javascript library into sprockets. I'm sure they will be able to help you way better than I would.

Besides that, I think that you might need to initialize each field separately, I'm pretty sure that is why it's failing: the default initialization method will look for forms with the dropzone class and then init dropzone on every [type=file] field, and that doesn't seem to be what you're looking for.

I'm sorry I can't assist you any better than this, but I'm really confident that you'll be able to get in the right direction if you try initializing dropzone js yourself instead of relying on the default initialization method.

sanjams2 commented 9 years ago

@ncuesta thanks for the quick response. I guess the biggest problem is I'm not very competent in rails development. I asked on the dropzone repo, but no one seems to be moderating that thread any longer. Im going to continue my search, but any adive you can give in begining to initialize dropzone myself? Thanks a lot though fro what you have given me now, I was way more stuck before.

ncuesta commented 9 years ago

@jsanders67 Sure, take a look at the docs.