I have a question about yii2 kartik-v widget select 2.
the widget is attached to the field in my view
<?=
$form->field($model, 'address')->widget(Select2::className(), [
'options' => ['placeholder' => 'Inserta an address '],
'pluginOptions' => [
'allowClear' => true,
'minimumInputLength' => 3,
'ajax' => [
'url' => Url::to(['register/addresses']),
'dataType' => 'json',
'data' => new JsExpression('function(params) { return {q:params.term}; }')
],
'escapeMarkup' => new JsExpression('function (markup) { return markup; }'),
'templateResult' => new JsExpression('function(address) { return address.name; }'),
'templateSelection' => new JsExpression('function (address) { return address.name; }'),
],
'pluginEvents' => [
"select2:select" => "function(e) {
// some function
}",
],
]);
?>
if in my controller I want to set the value in this field
like: $model->address = "Some Value";field remains blank in the view
What can I do?
UPDATE!
As the documentation says, I can use this option: initValueText if I use a version of this ajax plugin. So I tried to set 'initValueText' => $model->address,, but the result is the same
source
share