2017 © Pedro Peláez
 

yii2-extension yii2-select2

The Select2 widget for the Yii framework

image

indicalabs/yii2-select2

The Select2 widget for the Yii framework

  • Saturday, March 3, 2018
  • by indicalabs
  • Repository
  • 1 Watchers
  • 0 Stars
  • 213 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

Select2 for Yii2

Wrapper Widget to use jQuery Plugin Select2 in Yii2 application., (*1)

Select2 script: https://github.com/ivaynberg/select2, (*2)

Installation

Download or clone this repository and paste in /PROJECT-ROOT/vendor/yiisoft/yii2-select2/yii/select2, (*3)

Configure this extension in /PROJECT-ROOT/vendor/yiisoft/extensions.php, (*4)

'yiisoft/yii2-typeahead' => array ( 'name' => 'yiisoft/yii2-typeahead', 'version' => '9999999-dev', 'alias' => array ( '@yii/typeahead' => $vendorDir . '/yiisoft/yii2-typeahead/yii/typeahead', ), ),, (*5)

Usage

In your view file (_form.php) $model, 'attribute' => 'country_id', 'clientOptions' => [ //'local' => [], 'name' => 'country_id', 'limit' => 1, 'valueKey' => 'text', 'remote' => [ 'url' => Yii::$app->urlManager->createAbsoluteUrl('data/country/findcountry'). '&term=%QUERY', // 'cache' => false, ], 'engine' => new yii\web\JsExpression('Hogan'), 'template' => ', (*6)

{{id}}{{text}} - {{id}}, (*7)

', ], 'events' => [ 'selected' => new yii\web\JsExpression("function(evt,data) { alert(data); };"), ], ]); ?>
Or in config
```php
    ...
    'import' => array(
        ...
        'ext.select2.Select2',
        ...
    ),
    ...

Example:

You can replace the
CHtml::dropDownList() by Select2::dropDownList()
CHtml::activeDropDownList() by Select2::activeDropDownList(), (*8)

Or, (*9)

    ...
    echo Select2::multiSelect("test", null, array('test1','test2'), array(
        'required' => 'required',
        'placeholder' => 'This is a placeholder',
        'select2Options' => array(
            'maximumSelectionSize' => 2,
        ),
    ));
    ...
    echo Select2::activeMultiSelect($model, "attr", array('test1','test2'), array(
        'placeholder' => 'This is a placeholder',
    ));
    ...

Or this, (*10)

    ...
    $this->widget('Select2', array(
       'name' => 'inputName',
       'value' => 2,
       'data' => array(
           1 => 'Option 1',
           2 => 'Option 2',
           3 => 'Option 3',
           4 => 'Option 4',
        ),
    ));
    ...

The Versions

03/03 2018

dev-master

9999999-dev

The Select2 widget for the Yii framework

  Sources   Download

BSD-3-Clause

The Requires

  • php >=5.4.0
  • npm-asset/select2-bootstrap-theme ~0.1.0-beta.10
  • npm-asset/vue-select ~2.4.0
  • yiisoft/yii2 >=2.0.14
  • npm-asset/select2 4.0.5

 

by Venu Narukulla

yii2 widget select2