I have a select 2 multi-select option
<select multiple name="event_type[]" class="form-control" id="selectEvents">
@foreach ($eTypes as $type)
<option>{{$type}}</option>
@endforeach
</select>
I want to set some default values just in case the user is editing the form.
I have successfully done that by doing this
var s2 = $("#selectEvents").select2({
placeholder: "Choose event type",
tags: true
});
s2.val(["Trade Fair", "CA", "Party"]).trigger("change"); //CA doesn't show as a default
But the problem is i am allowing user generated options using the tags: true
option for select2.
When I set a default value that was initially in the html options it works, but when I set a default that was user generated it doesn't work.
It is my first time using select2.
How can i achieve this?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…