select2: default selection in multiple select with AJAX

Gabriel Sanmartin picture Gabriel Sanmartin · Apr 22, 2013 · Viewed 38.5k times · Source

I am using the awesome select2 to create a multiple selection combo.

I would like to programmatically select default values (as in selections the user has made previously), but I don't know how. I read that using initSelection does the trick but this is called when creating the combo and I don't want this default selection to be always done.

Answer

Ramin Firooz picture Ramin Firooz · Dec 18, 2016

right solution in version 4.x by example:

$('#element').val(['val1','val2']).trigger('change');

see: Creator description