Skip to content

Instantly share code, notes, and snippets.

@vishin-pavel
Created May 19, 2017 07:32
Show Gist options
  • Save vishin-pavel/9fe80723d05680c0fc330c67f00f850e to your computer and use it in GitHub Desktop.
Save vishin-pavel/9fe80723d05680c0fc330c67f00f850e to your computer and use it in GitHub Desktop.
Автокоплит инпут для Yii2 с возмоностью использовать Id вместо значения
<?php
//http://stackoverflow.com/questions/25708344/yii2-autocomplete-save-the-id-instead-of-value
use yii\web\JsExpression;
use yii\jui\AutoComplete;
$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 ) {
$('#model-company').val(ui.item.id);
}")],
]);
?>
<?= Html::activeHiddenInput($model, 'company')?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment