Kingra Morr
Kingra Morr

Reputation: 45

How can change maxFiles in dropzone dynamically?

I have a select option element in my project with two options, books and images. For book option, I want to allow only single file to upload. But for images option I need to allow multiple file selection. I am trying to this way but not succeeded:

 Dropzone.options.frmMediaDropzone = {
   maxFilesize: 99,
   acceptedFiles: ".jpeg,.jpg,.png,.gif,.pdf",
   parallelUploads: 1,
   addRemoveLinks: true,
   maxFiles: 100,
   init: function() {
     myDropzone = this;
     this.on("removedfile", function(file) {
       console.log(file);
     });

     this.on("success", function(file, response) {
       console.log(response.imageName);
     });
   }
 };

On option change, I am trying this:

Dropzone.options.frmMediaDropzone.maxFiles = 1;

But its not working. If anyone has idea please help.

Upvotes: 0

Views: 1522

Answers (2)

Mayank Majithia
Mayank Majithia

Reputation: 1966

Try this way to solve your problem,

you need to define a variable in javascript.

var myDropZone;

Initialize myDropZone vairable in init() event.

init: function() {

    myDropzone = this;
}

myDropzone became accessible so the statement

myDropzone.options.maxFiles = 1;

set clickable:false after a file upload done,

myDropzone.options.clickable = false;

remove file mannually after exceed max file limit.

myDropzone.on("maxfilesexceeded", function(file) {
    myDropzone.removeFile(file);
});

Upvotes: 1

Ryan Gibbs
Ryan Gibbs

Reputation: 1310

There a two ways of doing this. You can either dynamically create your dropzone and then change the attributes of it using .attr, or create a listener event in your init property when you define the dropzone.

See this link for a similar example (See the 2nd answer): Dropzone: change acceptedFiles dynamically

Upvotes: 0

Related Questions