Yii2 auto complete - value missing from field on update

I am using yii2 full set widget, it works fine except when I update the form the field shows blank.

use yii\jui\AutoComplete;
use yii\web\JsExpression;

$data = app\models\Doctor::find()
    ->select(['doctor_name as value', 'doctor_name as  label','id as id'])
    ->asArray()
    ->all();

      

and after that autocomplete code like this

echo 'Doctor' .'<br>';
  echo AutoComplete::widget([
    'name' => 'Doctor',    
    'id' => 'ddd',
    'clientOptions' => [
        'source' => $data, 
        'autoFill'=>true,
         'select' => new JsExpression("function( event, ui ) {
        $('#appoinment-doctor_name').val(ui.item.id);
     }")],
     ]);
<?= Html::activeHiddenInput($model, 'doctor_name')?>

      

What am I missing here? How can I get the value on update?

+3


source to share


1 answer


You must explicitly set value

:

echo AutoComplete::widget([
    'name' => 'Doctor',    
    'id' => 'ddd',
    'value' => $model->doctor_name,
    ...

      



This is not necessary if you have installed model

and attribute

.

+2


source







All Articles