项目作者: muhiddingithub

项目描述 :
yii2-autocomplete jquery ui
高级语言: JavaScript
项目地址: git://github.com/muhiddingithub/yii2-autocomplete.git
创建时间: 2017-10-25T07:33:08Z
项目社区:https://github.com/muhiddingithub/yii2-autocomplete

开源协议:MIT License

下载


yii2-autocomplete

yii2-autocomplete jquery ui

Installation

The preferred way to install this extension is through composer.

Either run

  1. php composer.phar require muhiddingithub/yii2-autocomplete "dev-master"

or add

  1. "muhiddingithub/yii2-autocomplete": "dev-master"

to the require section of your composer.json file.

Jquery source

Usage

  1. echo \muhiddin\autocomplete\AutoComplete::widget([
  2. 'id' => 'search',
  3. 'form'=>$form, // ActiveForm widget object
  4. 'model'=>$model, // model
  5. 'attribute'=>'model_attribute', // attribute of model
  6. 'value' => '',
  7. 'name' => 'name',
  8. 'options' => [
  9. 'class' => 'form-control form-group-margin',
  10. 'dir' => "ltr",
  11. 'placeholder' => "search",
  12. ],
  13. 'pluginOptions' => [
  14. 'minChars' => 3,
  15. 'serviceUrl' => \yii\helpers\Url::toRoute(['custom-controlller/customer-action']),
  16. 'width' => '40%',
  17. 'onSelect' => 'function(suggestion){
  18. // call onselect found element function
  19. }'
  20. ]
  21. ])

in custom-controlller/customer-action

  1. $query = Yii::$app->request->get('query');
  2. if (!empty($query)) {
  3. $find = MyModel::find()->andFilterWhere(['like','column_name',$query]);
  4. $allModels = $find->column();
  5. echo json_encode([
  6. 'suggestions' => $allModels
  7. ]);
  8. } else {
  9. echo json_encode(['status' => 'failure']);
  10. }