5

I just use my code like this

Dropzone.options.attachkyc = {
            maxFiles: 1,
            accept: function(file, done) {
            console.log("uploaded");
            done();
            },
            init: function() {
                this.on("maxfilesexceeded", function(file){
                    alert("No more files please!");
                });
            },
            addRemoveLinks: true,
            removedfile: function(file) {
                var name = file.name;        
                $.ajax({
                    type: 'POST',
                    url: host+'upload/unfile',
                    data: "id="+name,
                    dataType: 'html'
                });
                var _ref;
                return (_ref = file.previewElement) != null ? _ref.parentNode.removeChild(file.previewElement) : void 0;   

                //console.log();
            }
        };

When i upload second file is show alert "No more files please!", well is working taht file not uploaded, but my problem is, that second file i'm add it still show on my dropzone. My question is how i'm remove second file automaticly after i show the alert??

3 Answers 3

5

if you want to remove max file extended file you just have to use maxfilesexceeded method of dropzone

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

or you can also used one other method too

  init: function() {
  myDropzone.on("addedfile", function (file) {

                if (myDropzone.files.length === 1) {
                    alert("You can Select upto 1 Pictures for Venue Profile.", "error");
                    this.removeFile(file);
                }

            });
 },
Sign up to request clarification or add additional context in comments.

4 Comments

the first solution is better. Tq :)
if i have 100 files i will get 99 alerts
Is there any way to stop propagation .on("maxfilesexceeded", function (file) { ? Thanks.
@diesel94 this answer should handle that: stackoverflow.com/a/78984516/1662230
0

I finaly sovle my problem. on at

 init: function() {
            this.on("maxfilesexceeded", function(file){
                alert("No more files please!");
            });
        },

i change it into like this

init: function() {
            this.on("maxfilesexceeded", function(file){
                alert("No more files please!");
                this.removeFile(file);
            });
        },

is work perfectly i want.

1 Comment

if you have overflowing by many files, for example 100 files when 1 is allowed you will get 99 alerts.
0

If you are looking to keep the newly added file and remove the first file that was added you can do something like what is below:

 init: function() {
   myDropzone.on("maxfilesexceeded", function(file) {
     this.removeFile(this.files[0]);
  });
 },

You could obviously update the index of this.files to access other files in the array as well.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.