0
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');

1 Answer 1

1

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()

  • but you do not pass such object

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.

  • but you do not wait for the page to be ready

i hope this will give you some lead.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.