我试图将用户列表显示为mail.Here它是我的代码,但没有响应
canvas
答案 0 :(得分:0)
您需要使用label
作为自动完成输入值的显示值。
所以,user_email
为label
,如:
<?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) ?>