DropzoneJS&Laravel-输出表单验证错误 [英] DropzoneJS & Laravel - Output form validation errors

查看:33
本文介绍了DropzoneJS&Laravel-输出表单验证错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当您将鼠标悬停在Dropzone中放置的文件中的"X"上时,我正在尝试输出表单验证错误.

I am trying to output form validation errors when you hover over the "X" in the dropped off file in Dropzone.

我得到的东西:

如何使 object Object 输出来自表单验证的实际错误消息?我可以警告错误消息,但是将鼠标悬停在x上时实际上无法显示错误消息.

How can I make the object Object output the actual error message from the form validation? I can alert the error message but can't actually show the error message upon hovering over the 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',
    ]);

推荐答案

我已解决我的问题.

对于可能遇到相同问题的任何人.

To anyone who might have the same issue.

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

这篇关于DropzoneJS&Laravel-输出表单验证错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆