--
You received this message because you are subscribed to the Google Groups "select2" group.
To unsubscribe from this group and stop receiving emails from it, send an email to select2+u...@googlegroups.com.
To post to this group, send email to sel...@googlegroups.com.
Visit this group at http://groups.google.com/group/select2.
For more options, visit https://groups.google.com/d/optout.
Thanks a lot
Sumesh
Hi,
I was trying to pragmatically set values in select2(v4) having multiple selection and Ajax
I tried the solution mentioned by Paul, but didn't worked.
But it worked in the case of single-selection select2
This is how I set the data. Please help
var s2 = $("#selectelement").data('select2');
s2.trigger('select', {
data: [{"id":"15","text":"T1"},{"id":"28","text":"T2"}]
});
Its not working.
var control = $('#selectControl').data('select2');
var adapter = control.dataAdapter;
adapter.addOptions(adapter.convertToOptions(response));
$('#selectControl').trigger('change');
// Set up the Select2 control
$('#mySelect2').select2({
ajax: {
url: '/api/students'
}
});
// Fetch the preselected item, and add to the control
var studentSelect = $('#mySelect2');
$.ajax({
type: 'GET',
url: '/api/students/s/' + studentId
}).then(function (data) {
// create the option and append to Select2
var option = new Option(data.full_name, data.id, true, true);
studentSelect.append(option).trigger('change');
// manually trigger the `select2:select` event
studentSelect.trigger({
type: 'select2:select',
params: {
data: data
}
});
});