I’m having problem trying to save Place.id into $model->placeID.
I’ve created a field that will help the user to autocomplete the names of the place (place->name) but I would like to store the corresponding place id (place->id) into the database instead.
The autocomplete works but I’m unable to retrieve the place.id and store it into the database.
Please help. Thanks.
use yii\web\JsExpression;
use yii\jui\AutoComplete;
$data = Place::find()
->select(['name as value', 'name as label','id as id'])
->asArray()
->all();
?>
<?php echo $form->field($model,'placeID')->widget(\yii\jui\AutoComplete::classname(), [
'clientOptions' => [
'source' => $data,
'minLength'=>'2',
'autoFill'=>true,
'select' => new JsExpression("function( event, ui ) {
$('#placename').val(ui.item.id);
}")],
]);
?>