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

DropzoneJS & Laravel - Output form validation errors

当您将鼠标悬停在 Dropzone 中已删除文件中的 "X" 上时,我试图输出表单验证错误。

我得到的:

如何让 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',
    ]);

我已经解决了我的问题。

致所有可能遇到相同问题的人。

我通过简单地输入 $('.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);
        });
    });
}
};

如果您只想 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)