Хотел заюзать yii\jui\AutoComplete, пол дня провозился, так и не могу прикрутить, чтобы сохранялось не значение а id.
Вот контролеер
$scope = new Scope;
$scopeItems = $scope->find()
->select(['scope as value', 'scope as label', 'id as id'])
->asArray()
->all();
$vacancy = new Vacancy();
if ($vacancy->load(Yii::$app->request->post()))
{
$vacancy->scope_id = $scope->id;
if ($vacancy->save()){
$vacancy = new Vacancy();
}
else {
var_dump($vacancy->getErrors());
}
Вот сама форма
<div class="vacancy-form">
<?php Pjax::begin(['id' => 'new_vacancy']) ?>
<?php $form = ActiveForm::begin(); ?>
<?= $form->field($vacancy, 'title')->textInput(['maxlength' => true]) ?>
<?= $form->field($vacancy, 'text')->textarea(['rows' => 6]) ?>
<?= $form->field($vacancy, 'date')->widget(DatePicker::className(),['dateFormat' => 'dd-MM-yy', 'language' => 'ru']) ?>
<?= $form->field($vacancy, 'minprice')->textInput() ?>
<?= $form->field($vacancy, 'maxprice')->textInput() ?>
<?= $form->field($vacancy, 'employer_id')->textInput() ?>
<?= $form->field($scope, 'scope')->widget(AutoComplete::className(), [
'clientOptions' => [
'source' => $scopeItems,
'minLength'=>'2',
'options' => ['class' => 'form-control'],
]]) ?>
<?= $form->field($vacancy, 'skill_id')->textInput() ?>
<?= $form->field($vacancy, 'jobtime_id')->textInput() ?>
<?= $form->field($vacancy, 'city_id')->textInput() ?>
<?= $form->field($vacancy, 'mtop')->textInput() ?>
<div class="form-group">
<?= Html::submitButton($vacancy->isNewRecord ? 'Create' : 'Update', ['class' => $vacancy->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
</div>
<?php ActiveForm::end(); ?>
<?php Pjax::end(); ?>
</div>
Жду помощи