DropzoneJS和Laravel - 输出表单验证错误

3
我正在尝试在Dropzone中的已删除文件的“X”上悬停时输出表单验证错误。
我得到的结果是: enter image description here 如何使“object Object”输出实际的表单验证错误消息?我可以弹出错误消息,但无法在悬停在x上时显示错误消息。
我的js文件:
 Dropzone.options.fileupload = {
    maxFilesize: 20,

    init: function () {
        thisDropzone = this;
        this.on("error", function (file, responseText) {

                $.each(responseText, function (index, value) {
                    alert( value); //this shows the alert of the error message

                });


        });
    }
};

我的控制器:

$this->validate($request, [
        'file' => 'max:20000',
    ]);

对于任何寻求解决方案的人,请查看 stackoverflow.com/a/66603779/5723524 - Francesco Taioli
2个回答

1
我已经解决了我的问题。
对于任何可能遇到同样问题的人。
我通过简单地添加 $('.dz-error-message').text(value); 来解决它。
完整代码:
Dropzone.options.fileupload = {
maxFilesize: 50,
init: function () {
    thisDropzone = this;
    this.on("error", function (file, responseText) {
        $.each(responseText, function (index, value) {
            $('.dz-error-message').text(value);
        });
    });
}
};

0

如果你只想使用 Laravel 的验证错误,请使用这个。

...
        init: function () {
            thisDropzone = this;
            this.on("error", function (file, responseText) {
                $.each(responseText, function (index, value) {
                    if (index === 'errors'){
                        $('.dz-error-message').text(value.file);
                    }
                });
            });
        },
...

或者如果你只想要 dropzone.js 的错误输出更改。

if(index === message)

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接