最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Dropzonejs: change maxFiles programmatically - Stack Overflow

programmeradmin1浏览0评论

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.

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.

Share Improve this question asked Aug 30, 2014 at 7:02 lupantlupant 1311 silver badge5 bronze badges 1
  • You are resetting the variable contained in the dropzone options object, but the instance of dropzone that youve instantiated is not being modified. You will need to reinitialize the plugin: $('.dropzone').dropzone(newOptions); – bencripps Commented Aug 30, 2014 at 10:08
Add a ment  | 

1 Answer 1

Reset to default 7

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.

发布评论

评论列表(0)

  1. 暂无评论