I just set up a form (binded on a model) with some text fields, chechboxes and selections qith laravel 5.1.
Like the title sais I am am using form model binding. That works fine for the text fields and textareas when I want to update the model. Problem is that Checkboxes aren't checked and Selections aren't selected.
Printing out the model in the view everything looks good.
What I need:
- Prechecked / selected fields when displaying the form (Data from Model)
- Prechecked / selected fields on update with validation errors (old Input Data)
I just tried to do something like that:
<input type="checkbox" name="active" id="active" value="1" @if(old('active') == 1) checked @elseif(old('active') == 0) @elseif($model->active == 1) checked @endif>
(dirty shit that even doesn't work because old('active') returns '1' even if form hasn't submitted) -> there must be a better way :(
Like I said textfields and textareas are working like a charm.
Any idea? If you need to see more code please let me know.
Thanks
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire