26/10
2017
yii2-autocomplete jquery ui
yii2-autocomplete jquery ui, (*1)
The preferred way to install this extension is through composer., (*2)
Either run, (*3)
php composer.phar require muhiddingithub/yii2-autocomplete "dev-master"
or add, (*4)
"muhiddingithub/yii2-autocomplete": "dev-master"
to the require section of your composer.json
file., (*5)
Jquery source, (*6)
echo \muhiddin\autocomplete\AutoComplete::widget([ 'id' => 'search', 'form'=>$form, // ActiveForm widget object 'model'=>$model, // model 'attribute'=>'model_attribute', // attribute of model 'value' => '', 'name' => 'name', 'options' => [ 'class' => 'form-control form-group-margin', 'dir' => "ltr", 'placeholder' => "search", ], 'pluginOptions' => [ 'minChars' => 3, 'serviceUrl' => \yii\helpers\Url::toRoute(['custom-controlller/customer-action']), 'width' => '40%', 'onSelect' => 'function(suggestion){ // call onselect found element function }' ] ])
$query = Yii::$app->request->get('query'); if (!empty($query)) { $find = MyModel::find()->andFilterWhere(['like','column_name',$query]); $allModels = $find->column(); echo json_encode([ 'suggestions' => $allModels ]); } else { echo json_encode(['status' => 'failure']); }