Yii2自动完成无响应

时间:2015-11-05 08:33:17

标签: autocomplete yii2

我试图将用户列表显示为mail.Here它是我的代码,但没有响应

canvas

1 个答案:

答案 0 :(得分:0)

您需要使用label作为自动完成输入值的显示值。

所以,user_emaillabel,如:

<?php
 use yii\web\JsExpression;


 $data = Users::find()
         ->select(['user_email as value', 'user_id as id', 'user_email as label'])
         ->asArray()
        ->all();

 // OR try below query for get data.

 $data = (new \yii\db\Query())
        ->select(["user_email as value", "user_email as label","user_id as id"])
        ->from('users u')
        ->all();


  echo AutoComplete::widget([
    'name' => 'user_email',
    'id' => 'ddd',
    'clientOptions' => [
    'source' => $data,
    'autoFill'=>true,
    'minLength'=>'1',
    'select' => new JsExpression("function( event, ui ) {
        $('#".Html::getInputId($model, 'user_email')."').val(ui.item.id); // Html::gtInputId() get dynamic id of input field.

     }")],
     ]);
            ?>
<?= $form->field($model, 'user_email')->hiddenInput()->label(false) ?>