jQuery   发布时间:2022-03-30  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了javascript – 提交表单后重新初始化/重置dropzone大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

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

<div class="row">
  <div class="col-md-12" id="drop-zone-container">
    <%= form_tag '/settlement_proofs', method: :post, class: 'dropzone form', id: 'media-dropzone' do %>
        <div class="fallBACk">
          <%= file_field_tag 'attachment', multiple: true%>
        </div>
    <% end %>
  </div>
</div>

我将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提交表单后,我需要使用@L_197_3@认图像重置dropzone字段.

解决方法:

this.on("complete", function(filE) { 
   this.removeAllFiles(true); 
})

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

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

http://www.dropzonejs.com/#event-reset

大佬总结

以上是大佬教程为你收集整理的javascript – 提交表单后重新初始化/重置dropzone全部内容,希望文章能够帮你解决javascript – 提交表单后重新初始化/重置dropzone所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签: