diff --git a/xadmin/static/xadmin/js/xadmin.plugin.quick-form.js b/xadmin/static/xadmin/js/xadmin.plugin.quick-form.js index 779300d53..9bfcb5130 100644 --- a/xadmin/static/xadmin/js/xadmin.plugin.quick-form.js +++ b/xadmin/static/xadmin/js/xadmin.plugin.quick-form.js @@ -90,7 +90,7 @@ }, this)) .fail($.proxy(function(xhr) { this.$mask.hide(); - alert(typeof xhr === 'string' ? xhr : xhr.responseText || xhr.statusText || 'Unknown error!'); + alert(typeof xhr === 'string' ? xhr : xhr.responseText || xhr.statusText || 'Unknown error!'); }, this)); } , save: function(newValue) { @@ -108,16 +108,31 @@ // } // }) + var $nonfile_input = this.$form.serializeArray(); + + var formData = new FormData(); + + $nonfile_input.forEach(function(field) { + formData.append(field.name, field.value) + }); + + var $file_input = this.$form.find("input[type=file]"); + $file_input.each(function (idx, file) { + formData.append($(file).attr('name'), file.files[0]); + }); + return $.ajax({ - data: [this.$form.serialize(), $.param(off_check_box)].join('&'), + data: formData, url: this.$form.attr('action'), type: "POST", dataType: 'json', + contentType: false, + processData: false, beforeSend: function(xhr, settings) { xhr.setRequestHeader("X-CSRFToken", $.getCookie('csrftoken')); } }) - }, + }, } $.fn.ajaxform = function ( option ) { @@ -167,7 +182,7 @@ if(!this.modal){ var modal = $('