Select2 with remote data
Select2 with remote data
Hi,
I'm trying to use select2 into my editor.
I followed some discussions in this forum and (finally) I can use select2 with remote data (ajax).
I have only one issue: if I open the editor in edit mode, select2 doesn't show the stored value but, if I update the value again and I save, it show me the stored value.
I think that the problem is the "initSelection" (retired in version 4 of select2) or the set in editor.select2.js (set doesn't work with the remote data).
Can you help me to find the root cause?
Follow the code:
"type": "select2",
opts: {
ajax: { url: "batch/terminal_masterdata.php",
dataType: 'json',
delay: 250,
data: function (params)
{ return { q: params.term, // search term
page: params.page
};
},
processResults: function (data, page)
{ // parse the results into the format expected by Select2.
// since we are using custom formatting functions we do not need to
// alter the remote JSON data
return {
results: data
};
},
},
placeholder: 'Select an option',
escapeMarkup: function (markup) { return markup; }, // let our custom formatter work
minimumInputLength: 1,
cache: true,
tags: true,
//dataAdapter: customAdapter,
createTag: function (params) {
return { id: params.term,
text: params.term,
newOption: true
}
},
templateResult: function (data) {
var $result = $("<span></span>");
$result.text(data.text);
if (data.newOption) {
$result.append(" <em>(new)</em>");
}
return $result;
}
},
Replies
Maybe this will help you
https://datatables.net/forums/discussion/34385/select2-plugin-set-method-after-update-not-working-as-expected-solution-included
If the thread from zajc doesn't help, could you link to a test page showing the issue so I can debug it please.
Allan