Try to set selected multiple value of select option. But error when try to add another option
<select id="flag" class="flag" name="flag[]" multiple="multiple" class="form-control" style="width: 100%">
</select>
JS
var data="[";
for (var i=0;i<5;i++){
data+="{\"id\":\""+i+"\",";
data+="\"text\":\""+i+"\"}";
if(i<4){
data+=",";
}
}
data+="]";
data = JSON.parse(data);
$('.flag').select2({
data:data
});
$('#flag').val([1,2]);
$('#flag').trigger('change');
Try to set it with script above. The value in the select input field is run correctly like image below.
But as you can see, number 1 and 2 is not selected in dropdown option. So, when i try to click option "3". I expect it will shows 1,2,3. But the output is only "3", "1" and "2" is disappear.
Is it how it's done or am i missing something?
Currently using select2 v4
