【问题标题】:Can't display validation errors with kartik-v bootstrap file input plugin无法使用 kartik-v 引导文件输入插件显示验证错误
【发布时间】:2016-12-01 17:17:49
【问题描述】:

我在github插件上开了一个issue,但是好像不是很活跃,所以我也在这里问了。

我正在通过 ajax 发送我的文件,但是当上传失败时(因为高度太小)我没有收到真正的错误消息,但是我从我的 ajax url 中收到了一个错误,但是这个没有任何意义,因为什么都没有发送。 我认为不应该调用 ajax 路由,但无论如何,我尝试使用 'fileuploaderror' 并且确实得到了想要的错误,但我不知道如何显示它们。 fileuploaderror事件中一定有简单的方法,但我不知道。 谁能帮我解决这个问题?

Issue link | Plugin page

谢谢

$("#id").fileinput({
    uploadUrl: "/ajax/snippet/image/send/78", // server upload action
    deleteUrl: "/ajax/snippet/image/remove/",
    uploadAsync: false,
    showUpload: false, // hide upload button
    showRemove: false, // hide remove button
    maxFileCount: maxFile,
    browseOnZoneClick: true,
    language: "fr",
    minImageWidth: 150,
    minImageHeight: 150,
    allowedFileExtensions: ["jpg", "jpeg", "gif", "bmp", "png"],
    multiple: true,
    maxFileSize: 5000,
    uploadExtraData: function (previewId, index) {
        return {key: index};
    },
    initialPreviewAsData: true,
    overwriteInitial: false,
    }).on("filebatchselected", function (event, files) {
        // trigger upload method immediately after files are selected
        $(this).fileinput("upload");
    }).on('fileuploaderror', function (event, data, msg) {
        var form = data.form, files = data.files, extra = data.extra,
                response = data.response, reader = data.reader;
        // get message
        alert(msg);
    });
}

【问题讨论】:

    标签: javascript jquery ajax twitter-bootstrap


    【解决方案1】:

    好的,我得到了答案,在我的“filebatchselected”事件中,我正在强制上传。

    我需要先检查我是否有要上传的有效文件。

    $("#id").fileinput({
        uploadUrl: "/ajax/snippet/image/send/78", // server upload action
        deleteUrl: "/ajax/snippet/image/remove/",
        uploadAsync: false,
        showUpload: false, // hide upload button
        showRemove: false, // hide remove button
        maxFileCount: maxFile,
        browseOnZoneClick: true,
        language: "fr",
        minImageWidth: 150,
        minImageHeight: 150,
        allowedFileExtensions: ["jpg", "jpeg", "gif", "bmp", "png"],
        multiple: true,
        maxFileSize: 5000,
        uploadExtraData: function (previewId, index) {
            return {key: index};
        },
        initialPreviewAsData: true,
        overwriteInitial: false,
        }).on("filebatchselected", function (event, files) {
            // trigger upload method immediately after files are selected
            var filesStack = $('#input-id').fileinput('getFileStack');
            if (filesStack.length > 0) {
                $(this).fileinput("upload");
            }
        });
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-08-31
      • 1970-01-01
      • 2016-01-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多