muhiddingithub / yii2-autocomplete
yii2-autocomplete jquery ui
Installs: 128
Dependents: 0
Suggesters: 0
Security: 0
Stars: 3
Watchers: 2
Forks: 0
Open Issues: 0
Language:JavaScript
Type:yii2-extension
This package is not auto-updated.
Last update: 2024-05-12 02:29:40 UTC
README
yii2-autocomplete jquery ui Installation
The preferred way to install this extension is through composer.
Either run
php composer.phar require muhiddingithub/yii2-autocomplete "dev-master"
or add
"muhiddingithub/yii2-autocomplete": "dev-master"
to the require section of your composer.json
file.
Usage
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 }' ] ])
in custom-controlller/customer-action
$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']);
}