javascript - DropZone.js: How to disable file Uploading and only allow adding to dropzone via drag and drop - Stack Overflow

In dropzone (or vue2dropzone), is there a way to disable file uploading and only **allow adding to drop

In dropzone (or vue2dropzone), is there a way to disable file uploading and only **allow adding to dropzone via drag and drop.

I've a setup where I successfully setup a drag and drop to child Zones (clickable: .czs1,) in a dropzone using a custom preview Template as shown by AlexanderYW here in this issue How to properly add files manually?.

DropZone Options:

dropzoneOptions: {
    url: 'http://localhost:3000/imageUpload',
    thumbnailWidth: 250,
    autoProcessQueue: false,
    addRemoveLinks: true,
    clickable: `.czs1`,
    previewTemplate: this.template(),
  },

Now all I want to do is to disable childZones from triggering OS file Upload dialog box when clicked. I found that dropzone has the input tag hidden with a class dz-hidden-input

<input type="file" class="dz-hidden-input" style="visibility: hidden; position: absolute; top: 0px; left: 0px; height: 0px; width: 0px;">

so in the following, I get hold of inputs with .dz-hidden-input className and then event.preventDefault() for each however that does not work.

  var dropZoneInput = document.getElementsByClassName('dz-hidden-input')

  dropZoneInput.forEach(item => {
       item.addEventListener('click', function () {
           event.preventDefault()
       })
  })

Is there a to achieve this in a standard API (provided by Dropzone). If not how this can be solved because the above document.getElementsByClassName('dz-hidden-input') does not work.

Thanks.

In dropzone (or vue2dropzone), is there a way to disable file uploading and only **allow adding to dropzone via drag and drop.

I've a setup where I successfully setup a drag and drop to child Zones (clickable: .czs1,) in a dropzone using a custom preview Template as shown by AlexanderYW here in this issue How to properly add files manually?.

DropZone Options:

dropzoneOptions: {
    url: 'http://localhost:3000/imageUpload',
    thumbnailWidth: 250,
    autoProcessQueue: false,
    addRemoveLinks: true,
    clickable: `.czs1`,
    previewTemplate: this.template(),
  },

Now all I want to do is to disable childZones from triggering OS file Upload dialog box when clicked. I found that dropzone has the input tag hidden with a class dz-hidden-input

<input type="file" class="dz-hidden-input" style="visibility: hidden; position: absolute; top: 0px; left: 0px; height: 0px; width: 0px;">

so in the following, I get hold of inputs with .dz-hidden-input className and then event.preventDefault() for each however that does not work.

  var dropZoneInput = document.getElementsByClassName('dz-hidden-input')

  dropZoneInput.forEach(item => {
       item.addEventListener('click', function () {
           event.preventDefault()
       })
  })

Is there a to achieve this in a standard API (provided by Dropzone). If not how this can be solved because the above document.getElementsByClassName('dz-hidden-input') does not work.

Thanks.

Share Improve this question asked Dec 18, 2019 at 12:04 appuappu 4811 gold badge8 silver badges28 bronze badges 1
  • Is there a reason event is not initialized anywhere? I suppose it's the argument of the function but it makes it unclear if your problem is there or somewhere else. – Florian Thuin Commented Dec 23, 2019 at 18:23
Add a ment  | 

1 Answer 1

Reset to default 4 +50

You are searching for clickable option

If true, the dropzone element itself will be clickable, if false nothing will be clickable.

You can also pass an HTML element, a CSS selector (for multiple elements) or an array of those. In that case, all of those elements will trigger an upload when clicked.

var dropZoneInput = document.querySelectorAll('.dz-hidden-input')

dropZoneInput.forEach(item => {
  new Dropzone(item, {
    clickable: false
  });
})
<link href="https://cdnjs.cloudflare./ajax/libs/dropzone/4.3.0/dropzone.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare./ajax/libs/dropzone/4.3.0/dropzone.js"></script>

<form action="/file-upload" class="dropzone dz-hidden-input">
  <div class="fallback">
    <input name="file" type="file" />
  </div>
</form>

<form action="/file-upload" class="dropzone dz-hidden-input">
  <div class="fallback">
    <input name="file" type="file" />
  </div>
</form>

If you want the whole body to be a Dropzone and display the files somewhere else you can simply instantiate a Dropzone object for the body, and define the previewsContainer option. The previewsContainer should have the dropzone-previews or dropzone class to properly display the file previews.

new Dropzone(document.body, {
  previewsContainer: ".dropzone-previews",
  // You probably don't want the whole body
  // to be clickable to select files
  clickable: false
});

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744849842a4597062.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信