kartik Select2 onChange and Ajax Call
In this example you can see a function userAlert() and this will call after typing in select2 text input
In below example you can also see ajax calling. In the parameter set your URL.
You can also set your own label in this example.
echo $form->field($model, 'user')->widget(Select2::classname(), [ 'options' => ['id' => 'user_id', 'class'=>'kartik2', 'title'=>'User', 'onchange' =>"userAlert();"], 'pluginOptions' => [ 'ajax' => [ 'url' => 'Your Url', 'dataType' => 'json', ], 'allowClear' => false, 'minimumInputLength' => 3, 'escapeMarkup' => new JsExpression('function (markup) { return markup; }'), 'templateResult' => new JsExpression('function(user) { return user.text; }'), 'templateSelection' => new JsExpression('function (user) { return user.text; }'), ], ])->label('Label you can set here');
Really awesome blog. Your blog is really useful for me. Thanks for sharing this informative blog. Keep update your blog.
ReplyDeletePHP Yii Developers in India