I have a repeating field which allows users to upload multiple files at once, using the https://github.com/DubFriend/jquery.repeater package.
I have a form request for validation, which works, but in the view I don't know how to highlight only the fields where errors are present. In the image below, only the first row contains an error, but both rows are highlighted.
In my form request I have the following:
public function rules()
{
return [
...
'task_files.*.file_path' => 'required|max:10000',
'task_files.*.title' => 'required|min:2|max:255',
'task_files.*.file_description' => 'required|min:2|max:255',
'task_files.*.file_type' => 'required|numeric',
];
}
In my view I have:
<div class="form-group{{ $errors->has('task_files.*.file_path') ? ' has-danger' : '' }}">
{{ Form::file('file_path', ['class' => 'file_input'])}}
@if ($errors->has('task_files.*.file_path'))
<div class="form-control-feedback">
{{ $errors->first('task_files.*.file_path') }}
</div>
@endif
</div>
Having a look at the ViewErrorBag class, I see that the key of the failing field is present, but how can I incorporate this into my view?
"task_files.0.file_description" => array:1 [▼
0 => "The file description is required"
]
Edit: When validation fails the fields are not created by a loop in the Blade template. I am using $repeater.setList()
to set the data using the Laravel old()
helper function.