Created
May 19, 2017 07:32
-
-
Save vishin-pavel/9fe80723d05680c0fc330c67f00f850e to your computer and use it in GitHub Desktop.
Автокоплит инпут для Yii2 с возмоностью использовать Id вместо значения
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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