I am new to laravel, and I just implemented form validation. I have set custom error messages in different languages for each error which worked fine before putting <... class="needs-validation" novalidate>. Now my custom error message won't show.
Here is the code I use for my form:
<form method="POST" action="{{ route('users.store')}}" class="needs-validation" novalidate>
@csrf
<div class="form-group mb-3 ">
<label for="first_name" class="form-label">{{__('users.First Name')}}</label>
<div>
<input name="first_name" id="first_name" class="form-control @error('first_name') is-invalid @enderror" placeholder="{{__('users.First Name')}}" value="{{ old('first_name') }}" required>
@error('first_name')
<span class="invalid-feedback">
<strong>
{{ $message }}
</strong>
</span>
@enderror
</div>
</div>
<div class="form-footer">
<button type="submit" class="btn btn-primary">{{ __('general.Add') }}</button>
</div>
</form>
It just doesn't go inside the @error('first_name) function.
I also use this for my javascript (from the official website):
<script>
(function () {
'use strict'
// Fetch all the forms we want to apply custom Bootstrap validation styles to
var forms = document.querySelectorAll('.needs-validation')
// Loop over them and prevent submission
Array.prototype.slice.call(forms)
.forEach(function (form) {
form.addEventListener('submit', function (event) {
if (!form.checkValidity()) {
event.preventDefault()
event.stopPropagation()
}
form.classList.add('was-validated')
}, false)
})
})()
</script>