I made a login and register modal with Laravel Auth and materializecss modals (They work the same as Bootstrap modals). Everything works fine except one thing.
There is a check when I submit my form for several thing: Do the email and password match? Does the email exist in the database etc.
When one of the checks fails the user will not login and an error will be stored in the php array: $errors.
The problem is that the modal closes when the form submits, which is fine when the login is good. But when the login fails and a error appears. Than the modal should be reopened and the error must be shown in the modal.
I tried many things but I don't have much experience with JS and jQuery. I hope somebody can help and explain how it works?
I solved the problem with this code:
if ($('div#login-email').hasClass('has-error')) {
$('#login-modal').modal('open');
}
if ($('div#login-password').hasClass('has-error')) {
$('#login-modal').modal('open');
}
Laravel adds a has-error class to the form-group where you did something wrong. So when there are no divs with the class: has-error, than everything is fine.
When there is a div with the class has-error, than you failed at some point. So the modal should re-open.