Reputation: 19
var selectedValues = new Array();
selectedValues[0] = "1";
selectedValues[1] = "4";
$('#select2-multiple-employees').select2('val', selectedValues);
It selects only the first index in the array of selectedValues. I'm using select2 version: 4.0.8
Is there another way to do this? It doesn't work for me
Solution: Adding under insert selectedValues
$('#select2-multiple-employees').trigger('change');
Upvotes: 0
Views: 58
Reputation: 10122
here are 2 excerpts from select2
documentation:
Configuration: To configure custom options when you initialize Select2, simply pass an object in your call to .select2()
Basic Usage: The DOM cannot be safely manipulated until it is "ready". To make sure that your DOM is ready before the browser initializes the Select2 control, wrap your code in a
$(document).ready()
block.
i hope this will give you some lead.
Upvotes: 1