2017 © Pedro Peláez
 

yii2-extension yii2-autocomplete-ajax

A simple way to search model id of the attributes model.

image

oleyur/yii2-autocomplete-ajax

A simple way to search model id of the attributes model.

  • Tuesday, August 30, 2016
  • by oleyur
  • Repository
  • 1 Watchers
  • 0 Stars
  • 29 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 17 Forks
  • 0 Open issues
  • 1 Versions
  • 4 % Grown

The README.md

yii2-autocomplete-ajax

This is the AutocompleteAjax widget and a Yii 2 enhanced wrapper for the Autocomplete | jQuery UI. A simple way to search model id of the attributes model., (*1)

Installation

The preferred way to install this extension is through composer., (*2)

Either add, (*3)

"require": {
    "oleyur/yii2-autocomplete-ajax": "*"
}

of your composer.json file., (*4)

Latest Release

The latest version of the module is v0.5.0 BETA., (*5)

Usage

View:, (*6)

use keygenqt\autocompleteAjax\AutocompleteAjax;

// Normal select with ActiveForm & model
= $form->field($model, 'user_id')->widget(AutocompleteAjax::classname(), [
    'multiple' => false,
    'url' => ['ajax/search-user'],
    'options' => ['placeholder' => 'Find by user email or user id.']
]) ?>

Controller:, (*7)

class AjaxController extends Controller
{
    public function actionSearchUser($term)
    {
        if (Yii::$app->request->isAjax) {

            $results = [];

            if (is_numeric($term)) {
                /** @var Tag $model */
                $model = Tag::findOne(['id' => $term]);

                if ($model) {
                    $results[] = [
                        'id' => $model['id'],
                        'label' => $model['email'] . ' (model id: ' . $model['id'] . ')',
                    ];
                }
            } else {

                $q = addslashes($term);

                foreach(Tag::find()->where("(`email` like '%{$q}%')")->all() as $model) {
                    $results[] = [
                        'id' => $model['id'],
                        'label' => $model['email'] . ' (model id: ' . $model['id'] . ')',
                    ];
                }
            }

            echo Json::encode($results);
        }
    }
}

License

yii2-autocomplete-ajax is released under the BSD 3-Clause License. See the bundled LICENSE.md for details., (*8)

The Versions

30/08 2016

dev-master

9999999-dev https://github.com/oleyur/yii2-autocomplete-ajax

A simple way to search model id of the attributes model.

  Sources   Download

BSD-3-Clause

The Requires

 

plugin extension yii2 jquery ajax widget autocomplete