html提交完重置表单,javascript – 提交表单后重新初始化/重置dropzone

我正在使用dropzone.js在ruby上上传图像.这是我的HTML代码

我将dropzone初始化为

$("#media-dropzone").dropzone({

acceptedFiles: pg.constants.ACCEPTED_FORMAT,

maxFilesize: pg.constants.ATTACHMENT_MAX_FILE_SIZE, //In MB

maxFiles: pg.constants.ATTACHMENT_MAX_SIZE,

addRemoveLinks: true,

removedfile: function (file) {

if (file.xhr.responseText.length > 0) {

var fileId = JSON.parse(file.xhr.responseText).id;

$.ajax({

url: pg.constants.url.SETTLEMENT_BASE_URL + fileId,

method: 'DELETE',

dataType: "json",

success: function (result) {

$('#uploaded_attachment').val($("#uploaded_attachment").val().replace(result.id + ',', ""));

$('#settlement_proof_status span').fadeOut(0);

var _ref;

return (_ref = file.previewElement) != null ? _ref.parentNode.removeChild(file.previewElement) : void 0;

},

error: function () {

$('#settlement_proof_status').text(I18n.t('attachment_deletion_error')).fadeIn();

}

});

}

},

init: function () {

this.on("success", function (file, message) {

debugger;

appendContent(message.attachment.url, message.id);

});

this.on("error", function (file, message) {

$('#settlement_proof_status span').text(message).fadeIn();

var _ref;

return (_ref = file.previewElement) != null ? _ref.parentNode.removeChild(file.previewElement) : void 0;

});

$('#settlement_invoice_submit_btn').click(function () {

$("#new_settlement_invoice").submit();

});

$('#uploaded_attachment').change(function () {

if (this.value.length == 0) {

this.removeAllFiles();

}

});

}

});

在我通过AJAX提交表单后,我需要使用默认图像重置dropzone字段.

解决方法:

this.on("complete", function(file) {

this.removeAllFiles(true);

})

在INIT函数中编写上面的代码.

这将删除dropzone中的所有文件,并将dropzone重置为初始状态.

标签:jquery,javascript,ruby-on-rails,dropzone-js

来源: https://codeday.me/bug/20190711/1434755.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值