Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dropzonejs: change maxFiles programmatically

I need to change maxFiles option programmatically. This is my init:

  Dropzone.options.dropzone = {
                    paramName: "files",
                    params:true,
                    url: "/upload.php",
                    autoProcessQueue: true,
                    uploadMultiple: true,
                    parallelUploads: 10,
                    maxFiles: fileleft,
                    previewsContainer: ".dropzone",
                    clickable: true,
                    addRemoveLinks: false,
                    acceptedFiles: '.jpg,.pdf,.png,.bmp',                        
                    dictInvalidFileType: 'Unsupported.',
                    accept: function(file, done) { 
                        done();

                    },
                    init: function() {

                        var myDropzone = this;

                        this.on("successmultiple", function(files, response) {
                            ins.pop_gallery(id);
                            this.removeAllFiles(); 

                        this.on("maxfilesexceeded", function(file){

                            this.removeFile(file);
                        });

                        this.on("sending", function(file, xhr, formData) {
                            formData.append("custom", id );

                        });
                    }

                }   

Everything is working correctly, but I need to change the maxFiles option value later.

I've tried this:

Dropzone.options.dropzone.maxFiles = fileleft;

and this:

myDropzone.maxFiles = fileleft;

but despite this code

alert(Dropzone.options.dropzone.maxFiles);

give me the correct answer, the maxFiles upload limit in fact is still unchanged.

Any thought?

Thanks.

like image 535
lupant Avatar asked Aug 30 '14 07:08

lupant


1 Answers

First of all, thank you for replaying. I have found some problem to reinitialize the plugin, at the end I think my error was in the init:

init: function() {

    var myDropzone = this;

redeclaring the var I was loosing the visibility in the further code.

So changing in

init: function() {

    myDropzone = this;

(without var)

myDropzone became accessible so the statement

myDropzone.options.maxFiles = fileleft;

now is working.

Thanks a lot.

like image 132
lupant Avatar answered Oct 10 '22 23:10

lupant