Solved : The error was because the Javascript rendered as String . It was solved by putting the javascript function in new yii\web\JsExpression(.....)
yii select2 AJAX error - data.call not a function
-
06-08-2022 - |
Question
Select2 ajax call is showing the below error When I click in the textfield, Nothing returns and below is the java script error in the firebug console.
TypeError: data.call is not a function
(?)() select2.js (line 431)
data = data ? data.call(self, query.term, query.page, query.context) : null;
Below is the call from THE VIEW: (yii2 framework)
<?= $form->field($model,'country_id')->widget(yii\select2\Select2::className(), [
'model'=>$model,
'attribute'=>’country_id',
// 'language' => 'ru',
// 'multiple' => true,
'clientOptions' => [
// 'allowClear' => true,
'width' => 300,
'ajax' => [
'url' => Yii::$app->urlManager->createAbsoluteUrl('data/country/findcountry') ,
'dataType' => 'json',
'data' => 'js:function(term,page) {
return {q: term, page: page, page_limit: 10};
}',
'results' => 'js:function(data,page) { return {results: data}; }',
],
],
]) ?>
Please can some one help? Thanks in advance
Solution
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow