2 months ago

Display old multiple select values with select2 jQuery

Posted 2 months ago by kriszpchicken

I am using the select2 jQuery function for my form, when selecting publishers and authors for my book. When I am sending the form, and if I mess up the title and get an error message, I want to still have the values I have selected displayed in the form. I could get it for the normal select box and the checkbox but I can't figure it out for the select2 multiple select boxes.

<div class="form-group">
                <label for="publishers">Verlag(e):</label>
                <select name="publishers[]" multiple class="form-control select2-multi <!-- @error('publishers') is-invalid @enderror -->">
                    @foreach ($publishers as $publisher)
                    <option value="{{ $publisher->id }}">{{ $publisher->name }}</option>
                <div class="alert alert-danger">{{ $message }}</div>

Please sign in or create an account to participate in this conversation.