Dropzone.js ... Requeue rejected the files ... trying to implement the github response in my script

When submitting a form, if there are errors in any of the form fields (for example, the name), the files must be reloaded by the user.

I am trying to implement this code in my script to fix this problem, but it does not work

Dropzone.prototype.requeueFiles = function(files){
    for (var i = 0, l = files.length, file; i < l; i++){
        file = files[i];
        file.status = Dropzone.ADDED;
        file.upload.progress = 0;
        file.upload.bytesSent = 0;
    }
}

//...on submit
self.requeueFiles(self.files);

Pay attention to the comment:

I think you may set the status to Dropzone.QUEUED

Here is my current code:

$(document).ready(function() {
  var dropzone;
  Dropzone.autoDiscover = false;
  dropzone = new Dropzone('#dropform', {
    maxFiles: 2,
    maxFilesize: 2.5,
    paramName: 'photo[picture]',
    headers: {
      "X-CSRF-Token": $('meta[name="csrf-token"]').attr('content')
    },
    addRemoveLinks: true,
    clickable: '.dz-default.dz-message',
    previewsContainer: '.dz-default.dz-message',
    thumbnailWidth: 200,
    thumbnailHeight: 200,
    parallelUploads: 100,
    autoProcessQueue: false,
    uploadMultiple: false
  });

  $('#item-submit').click(function(e) {
    e.preventDefault();
    e.stopPropagation();
    if (dropzone.getQueuedFiles().length > 0) {
      return dropzone.processQueue();
    } 
    else {
      return $('#dropform').submit();
    }
  });
  dropzone.on('error', function(file, errorMessage, xhr) {
    console.log('error');
    $('.idea').html(errorMessage + ".  Please try again.  Thank you.");
  });
  return dropzone.on('success', function(file, responseText) {
    return window.location.href = '/photos/' + responseText.id;
  });
});
+1
source share

Source: https://habr.com/ru/post/1568415/


All Articles