Search code examples
ruby-on-railsdropzone.jswebpacker

Setting Webpacker module options


I am a bit over my head - I have installed a few Webpacker modules in my Rails app - for example Dropzone:

require('dropzone')

I and it works - I have it on a page which I would like to specify the options:

https://www.dropzonejs.com/#configuration-options

like this for example:

Dropzone.options.newUpload = {
  paramName: 'upload[file]',
  maxFilesize: 100
}

I have tried adding this in several places including directly before the dropzone form in the view in a tag. No matter what the console throws errors (mostly 'Dropzone undefined' type errors).

I am guessing I am just not setting this correctly. Any tips / suggestions?


Solution

  • As you're using modules you should explicitly import from them

    import Dropzone from 'dropzone'
    
    Dropzone.options.newUpload = {
      paramName: 'upload[file]',
      maxFilesize: 100
    }
    

    Repeat this import in every your module that's using Dropzone because these names don't fall into global scope.