Answer the question
In order to leave comments, you need to log in
How to display get request in select2?
How to make it so that when they go to the get request, then in select2 it is displayed in value the value that came from the get request. Tried like this
Link is crm/frontend/web/create?phone=81111111111
<?= $form->field($client, 'phone')->widget(Select2::className(), [
'data' => ArrayHelper::map(Client::find()->all(), 'id', 'phone', 'fio'),
'value' => $_GET['phone'],//здесь должна отобразиться значение 81111111111
'options' => ['placeholder' => 'Введите номер телефона'],
'pluginOptions' => [
'allowClear' => true,
'language' => [
'noResults' => new JsExpression('function () { return "<a href=\"'. Url::to(['client/create']).'\">Добавить клиента</button>"; }'),
],
'escapeMarkup' => new JsExpression('function (markup) {
return markup;
}')
],
])?>
Answer the question
In order to leave comments, you need to log in
'value' => $_GET['phone'],//здесь должна отобразиться значение 81111111111
What do you think happens here?
And it turns out there:
[
'fio1'=>['id1'=>'phone1','id2'=>'phone2'],
'fio2'=>['id3'=>'phone3','id4'=>'phone4'],
]
ArrayHelper::map(Client::find()->all(), 'phone', 'phone'),
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question