I have a form that deletes a selected option (Office field on the gif) when there is a validation error. The other fields that had data entered remains in the field. I would like the Office field to keep the selected data if there is a validation error in a different field. How do I change the form to keep the selected option?
I’ve tried the code below, but it doesn’t work.
<select name="officename" id="ofiicename" class="form-control @error('officename') is-invalid @enderror">
<option value="">--Select the office--</option>
@foreach($clients as $val)
<option value="{{ $val->firstname }}" {{ old('officename') == $val->firstname ? 'selected' : '' }}>{{ $val->firstname }}</option>
Saving selected option after validation in Laravel I can’t use this code because all options for the dropdown aren’t listed in the form. Some options can be added later in a backend module.