Skip to content
Advertisement

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

Advertisement

Answer

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);
        });
    });
}
};
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement