Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DropzoneJS & Laravel - Output form validation errors

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

What I get:

enter image description here

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.

My js file:

 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

                });


        });
    }
};

My controller:

$this->validate($request, [
        'file' => 'max:20000',
    ]);
like image 875
Taylor Avatar asked Feb 27 '26 08:02

Taylor


1 Answers

I have fixed my issue.

To anyone who might have the same issue.

I fixed it by simply putting $('.dz-error-message').text(value);

Full code:

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);
        });
    });
}
};
like image 91
Taylor Avatar answered Feb 28 '26 21:02

Taylor