Select2 with remote data

Select2 with remote data

koko82koko82 Posts: 12Questions: 2Answers: 0

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
                                        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>");
                                        if (data.newOption) {
                                            $result.append(" <em>(new)</em>");
                                        return $result;


This discussion has been closed.