我正在开发一个自动完成小部件.到目前为止,这是我的代码.
我的看法:
<?php
$data = Company::find()
->select(['name as value', 'name as label','c_id as id'])
->asArray()
->all();
echo AutoComplete::widget([
'name' => 'Company',
'id' => 'ddd',
'clientOptions' => [
'source' => $data,
'autoFill'=>true,
'minLength'=>'4',
'select' => new JsExpression("function( event, ui ) {
console.log(ui);
$('#user-company').val(ui.item.id);
}")],
]);
?>
<?= Html::activeHiddenInput($model, 'company')?>
Run Code Online (Sandbox Code Playgroud)
选择选项时,自动填充选项将在我的文本字段中更新,但不会更新隐藏字段.
如何在选择选项时更新隐藏字段?