Answer the question
In order to leave comments, you need to log in
Yii2 AutoComplete how to insert into the field not id but name?
I use in Yii2 AutoComplete:
echo $form->field($model, 'city')->widget(AutoComplete::classname(), [
'clientOptions' => [
'source' => City::find()->select(['city_id as value', 'name as label'])->asArray()->all()
],
'options'=>[
'placeholder' => 'Ваш город (начните вводить)',
'class' => 'form-control form-control-signup input-sm select-registration'
]
])->label('');
Answer the question
In order to leave comments, you need to log in
Try 2 options:
1) source' => City::find()->select(['name as label'])->asArray()->all()
2) source' => City::find() ->select(['name as value', 'name as label'])->asArray()->all()
Instead of
should
ArrayHelper:map(City::find()->select(['city_id', 'name'])->all(),'name','name');
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question