【问题标题】:DropzoneJS & Laravel - Output form validation errorsDropzoneJS & Laravel - 输出表单验证错误
【发布时间】:2016-03-20 12:09:21
【问题描述】:

当您将鼠标悬停在 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',
    ]);

【问题讨论】:

  • 对于任何寻求解决方案的人,请查看 stackoverflow.com/a/66603779/5723524

标签: javascript php jquery laravel dropzone.js


【解决方案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);
        });
    });
}
};

【讨论】:

    【解决方案2】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-05-20
      • 2015-08-28
      • 2018-11-04
      • 1970-01-01
      • 1970-01-01
      • 2016-01-13
      • 2014-08-23
      相关资源
      最近更新 更多