Reputation: 125
I need to keep the checked checkboxes in the form as checked after I get the validation errors in the Controller.
Actually I find quite horrendous my implementation of the checkboxes in my form.
Could you please provide some advise? Thanks
<div class="form-group">
{!! Form::label('call', 'Llamar:', ['class' => 'control-label']) !!}
{!! Form::checkbox('call', isset($category)?(bool)$category->call:true, ['class' => 'form-control']) !!}
</div>
Upvotes: 0
Views: 1818
Reputation: 1145
You can do it via the form builder much easier like this:
{!! Form::checkbox('call', 1, false, ['class' => 'form-control']) !!}
That's all.
You don't need to worry about any kind of values, it will be set automatically.
Upvotes: 0
Reputation: 129
For the checkbox part, I did not use Laravel Forms. I used normal html "input" tag instead, and used "old" to check for previous value
<input type="checkbox" name="call" value="1" {{(old('call') == "1") ? 'checked': ''}}>Call
Try using old to check the previous value and set the value to checked or not based on that.
Upvotes: 1