X-Editable Select2 Remote Data Call Help

Hello,

Would like to ask if anyone can help me get an xeditable, select2 dropdown, remote data call working.

I also want the option to enter text not in the list.

XEDITABLE - Link with demos, but no detailed code or examples

http://vitalets.github.io/x-editable/demo-bs3.html

SELECT2 details - http://vitalets.github.io/x-editable/docs.html#select2

XEDITABLE docs say SOURCE needs to be array|string|function. Any ideas on a function to call ajax remote data?

***Updated - made a function as below. Need help to make it call this when select2 box is clicked.




                    [

                        'attribute' => 'test_id',

                        'format'=>'raw',

                        'label'=>'Subject',

                        'id' => 'test_input',

                        'value' => \mcms\xeditable\XEditableSelect::widget([

                            'model' => $model,

                            'placement' => 'right',

                            'emptytext' => 'Please select...',

                            'url' => '/test/editable',

                            'type' => 'select',

                            'pluginOptions' => [

                                // 'source' => $subjectList,

                                'source' => new \yii\web\JsExpression('function() {

                                        var subject_input = $(this).val();

                                        $.ajax({

                                                type :"GET",

                                                url : "/test/searchtests",

                                                data : "q="+test_input,

                                                dataType : "jsonp",

                                                success :function(data) {

                                                    console.log(data);

                                                    return data.id + data.name;

                                                },

                                                error :function(data) {

                                                    console.log(data);

                                                    alert(data);

                                                },

                                            });

                                }'),

                                'name' => 'subject_id',

                                'type' => 'select2',

                                'url' => '/exams/editable',

                                'onblur' => 'submit',

                                'emptyText' => 'None',

                                'select2' => [

                                    'placeholder' => 'Select a Subject',

                                    'allowClear' => true,

                                    'width' => '230px',

                                    'minimumInputLength' => 2,

                                ]

                            ],

                            

                            'callbacks' => [

                                'validate' => new \yii\web\JsExpression('

                                    function(value) {

                                        if($.trim(value) == "") {

                                            return "This field is required";

                                        }

                                    }

                                ')

                            ]


                        ]),

                    ],