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.
right solution in version 4.x by example:
$('#element').val(['val1','val2']).trigger('change');
see: Creator description
I found some solutions, maybe that will help you:
$('#el').select2({...}) // init select2 var defaultData = [{id:1, text:'Item1'},{id:2,text:'Item2'},{id:3,text:'Item3'}]; $('#el').data().select2.updateSelection(defaultData);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With