Skip to content

Instantly share code, notes, and snippets.

@madaarya
Created December 11, 2016 15:00
Show Gist options
  • Save madaarya/cb4196c25a0ede2b607b17aaef6b930c to your computer and use it in GitHub Desktop.
Save madaarya/cb4196c25a0ede2b607b17aaef6b930c to your computer and use it in GitHub Desktop.
dropzone example when use normal form submit
//= require dropzone
$(document).on("ready", function(){
Dropzone.autoDiscover = false;
new Dropzone('#postCreateForm',{
paramName: "post_images_attributes",
autoProcessQueue: false,
uploadMultiple: true,
clickable: '.js-input-create-dropzone',
maxFiles: 10,
addRemoveLinks: true,
previewsContainer: ".post-create-images-preview",
thumbnailWidth: 250,
thumbnailHeight: null,
init: function(){
var myDropzone = this;
this.on("addedfile", function() {
// action after add file
});
$('#postCreateForm input[type="submit"]').on("click", function (e) {
$(this).attr("disabled", "disabled");
if(myDropzone.getQueuedFiles().length > 0){
e.preventDefault();
e.stopPropagation();
myDropzone.processQueue();
}else{
$('form#postCreateForm').trigger('submit.rails');
}
});
this.on("success", function(files, response) {
window.location.href = '/stories/'+ response.storySlug;
});
this.on("error", function(files, response) {
$('input[type="submit"]').attr("disabled", false);
$(".error-message-content").html(" ");
$.each(files, function(i, val) {
files[i].status = Dropzone.QUEUED;
});
$.each(response, function( key, value ) {
$(".error-message-content").append(""+ key +" "+value[0]+"")
});
});
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment