0
For the problem below consider that I am using Laravel (5.6* with default style files and javascript (no changes).
My problem is basically when trying to display the validation message from the field group radio (id: genero), these are grouped in a fieldset. Validation occurs and in HTML (DOM) returned you can see the present message, but it is not being displayed on the screen.
Controller:
$this->validate($request, [
'name' => 'required|min:3',
'profissao' => 'min:3',
'biografia' => 'min:20',
'genero' => 'required|in:F,M,Não declarado',
'data_nascimento' => 'required'
]);
//...
View:
@if (session('status'))
<div class="alert alert-{{ session('status') }}">
<a href="#" class="close" data-dismiss="alert" aria-label="close">×</a>
{{ session('msg') }}
</div>
@endif
<!-- //... -->
<div class="form-group row">
<label for="genero" class="col-md-4 col-form-label text-md-right">Gênero</label>
<div class="col-md-6">
<fieldset id="genero">
<div class="form-check">
<label class="form-check-label">
<input type="radio" class="form-check-input{{ $errors->has('genero') ? ' is-invalid' : '' }}" name="genero" value="F" {{ $usuario->genero == 'F' ? 'checked' : '' }}>
Feminino
</label>
</div>
<div class="form-check">
<label class="form-check-label">
<input type="radio" class="form-check-input{{ $errors->has('genero') ? ' is-invalid' : '' }}" name="genero" value="M" {{ $usuario->genero == 'M' ? 'checked' : '' }}>
Masculino
</label>
</div>
<div class="form-check">
<label class="form-check-label">
<input type="radio" class="form-check-input{{ $errors->has('genero') ? ' is-invalid' : '' }}" name="genero" value="Não declarado" {{ $usuario->genero == 'Não declarado' ? 'checked' : '' }}>
Não declarado
</label>
</div>
</fieldset>
@if ($errors->has('genero'))
<span class="invalid-feedback">
<strong>{{ $errors->first('genero') }}</strong>
</span>
@endif
</div>
</div>
For the classes you are using Bootstrap, correct? The validation rule of this parameter is made with this syntax:
.was-validated .form-control:invalid~.invalid-feedback
, then you need the span ofinvalid-feedback
is the next element of itsform-control
. The entire documentation is here https://getbootstrap.com/docs/4.0/components/forms/– Kiss
Thanks, as only this particular form has the elements mentioned, I decided to do so:
<span class="invalid-feedback" style="display: block !important;">
– Fábio Jânio