Skip to content

I suggest adding a check for an error #985

Open
@spy-reality

Description

@spy-reality

/resources/views/bootstrap.php

errorPlacement: function (error, element) {
    if (element.parent('.input-group').length ||
        element.prop('type') === 'checkbox' || element.prop('type') === 'radio') {
        error.insertAfter(element.parent());
        // else just place the validation message immediately after the input
    } else {
        error.insertAfter(element);
    }
},

replace with

errorPlacement: function(error, element) {
    var existingError = element.next('.error-help-block'); // Checking the existence of an already displayed error
    if (existingError.length) {
        existingError.replaceWith(error); // Replacing an existing error with a new one
    } else {
        if (element.parent('.input-group').length ||
            element.prop('type') === 'checkbox' || element.prop('type') === 'radio') {
            error.insertAfter(element.parent());
        } else {
            error.insertAfter(element);
        }
    }
},

The form validation is done in php and an error is returned which is inserted like this

@error('username')
<span class="help-block error-help-block">{{ $message }}</span>
@enderror

The problem is that error.insertAfter does not replace this error.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions