2

I have a select2 on text input that allow multiple selected

I can't figure out how to set the initial values for it, I have below code. Any pointer would be appreciated. Thank you.

var $select = $('#cc_list');

    $select.select2({
        placeholder: "Search CC list",
        minimumInputLength: 1,
        ajax: { // instead of writing the function to execute the request we use Select2's convenient helper
            url: "../ajax/employee-select2.php",
            dataType: 'json',
            quietMillis: 250,
            data: function (term, page) {
                return {
                    query: term, // search term
                };
            },
            results: function (data, page) { // parse the results into the format expected by Select2.
                return { results: data };
            },
            cache: true
        },
         multiple: true,
         maximumSelectionSize: 5,
        dropdownCssClass: "bigdrop", 
        escapeMarkup: function (m) { return m; } 
    });

    $select.val('val1, val2').trigger('change');
everisk
  • 181
  • 2
  • 14
  • Possible duplicate of [Select2 4.0.0 initial value with Ajax](http://stackoverflow.com/questions/30316586/select2-4-0-0-initial-value-with-ajax) – Kevin Brown-Silva Nov 29 '15 at 19:27

0 Answers0