2017 © Pedro Peláez
 

yii2-extension select2

Yii2 Select2 widget

image

conquer/select2

Yii2 Select2 widget

  • Friday, October 27, 2017
  • by borodulin
  • Repository
  • 3 Watchers
  • 12 Stars
  • 6,655 Installations
  • PHP
  • 4 Dependents
  • 0 Suggesters
  • 7 Forks
  • 0 Open issues
  • 16 Versions
  • 9 % Grown

The README.md

Select2 widget for Yii2 framework

Description

Select2 gives you a customizable select box with support for searching, tagging, remote data sets, infinite scrolling, and many other highly used options. For more information please visit Select2, (*1)

Installation

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

To install, either run, (*3)

$ php composer.phar require conquer/select2 "*"

or add, (*4)

"conquer/select2": "*"

to the require section of your composer.json file., (*5)

Usage

Basic usage:, (*6)

// Form edit view
use conquer\select2\Select2Widget;
use yii\helpers\ArrayHelper;

$form->field($model, 'attribute')->widget(
    Select2Widget::className(),
    [
        'items'=>ArrayHelper::map(Catalog::find()->all(), 'id', 'name')
    ]
);

Ajax:, (*7)


use conquer\select2\Select2Action; ... class SiteController extends Controller { public function actions() { return [ 'ajax' => [ 'class' => Select2Action::className(), 'dataCallback' => [$this, 'dataCallback'], ], ]; } /** * * @param string $q * @return array */ public function dataCallback($q) { $query = new ActiveQuery(Catalog::className()); return [ 'results' => $query->select([ 'catalog_id as id', 'catalog_name as text', ]) ->filterWhere(['like', 'catalog_name', $q]) ->asArray() ->limit(20) ->all(), ]; } } // Form edit view: $form->field($model, 'attribute')->widget( Select2Widget::className(), [ 'ajax' => ['site/ajax'] ] );

Jquery Events:, (*8)

Array the Select2 JQuery events. You must define events in event-name => event-function format. All events will be stacked in the sequence. Refer the plugin options documentation for details., (*9)

For example:, (*10)


$form->field($model, 'attribute')->widget( Select2Widget::className(), [ 'events' => [ 'select2:open' => "function() { log('open'); }", ] ] );

Initialization of multiple selection in case of using ajax and custom templates., (*11)

<?= $form->field($model, 'multipleItems')->widget(Select2Widget::className(), [
    'options' => [
        'placeholder' => 'Select items ...',
    ],
    'ajax' => Url::to(['items/search']),
    'multiple' => true,
    'items' => ArrayHelper::map($model->multipleItems, 'id', 'text'),
    // Initial data the same, as returned results from Ajax request items/search
    'data' => $model->multipleItems,
    'settings' => [
        'ajax' => ['delay' => 250],
        'minimumInputLength' => 1,
        'minimumResultsForSearch' => -1,
        /** 
         * Handlebars here is used as example of using template engine
         * If you will not provide initial data,
         *   custom templates will not access additional info of items
         */
        'templateResult' => 'js:Handlebars.compile($("#template-result").html())',
        'templateSelection' => 'js:Handlebars.compile($("#template-selection").html())',
        'escapeMarkup' => 'js:function(markup){ return markup; }',
    ],
]) ?>

License

conquer/select2 is released under the MIT License. See the bundled LICENSE for details., (*12)

The Versions

27/10 2017

dev-release

dev-release https://github.com/borodulin/yii2-select2

Yii2 Select2 widget

  Sources   Download

MIT

The Requires

 

extension yii2 widget select2

27/10 2017

dev-master

9999999-dev https://github.com/borodulin/yii2-select2

Yii2 Select2 widget

  Sources   Download

MIT

The Requires

 

extension yii2 widget select2

10/01 2017

1.4.4

1.4.4.0 https://github.com/borodulin/yii2-select2

Yii2 Select2 widget

  Sources   Download

MIT

The Requires

 

extension yii2 widget select2

10/01 2017

1.5.4-beta

1.5.4.0-beta https://github.com/borodulin/yii2-select2

Yii2 Select2 widget

  Sources   Download

MIT

The Requires

 

extension yii2 widget select2

20/05 2016

1.5.3-beta

1.5.3.0-beta https://github.com/borodulin/yii2-select2

Yii2 Select2 widget

  Sources   Download

MIT

The Requires

 

extension yii2 widget select2

20/05 2016

1.4.3

1.4.3.0 https://github.com/borodulin/yii2-select2

Yii2 Select2 widget

  Sources   Download

MIT

The Requires

 

extension yii2 widget select2

09/12 2015

1.4.2

1.4.2.0 https://github.com/borodulin/yii2-select2

Yii2 Select2 widget

  Sources   Download

MIT

The Requires

 

extension yii2 widget select2

09/12 2015

1.5.2-beta

1.5.2.0-beta https://github.com/borodulin/yii2-select2

Yii2 Select2 widget

  Sources   Download

MIT

The Requires

 

extension yii2 widget select2

16/09 2015

1.4.1

1.4.1.0 https://github.com/borodulin/yii2-select2

Yii2 Select2 widget

  Sources   Download

MIT

The Requires

 

extension yii2 widget select2

16/09 2015

1.5.1-beta

1.5.1.0-beta https://github.com/borodulin/yii2-select2

Yii2 Select2 widget

  Sources   Download

MIT

The Requires

 

extension yii2 widget select2

23/08 2015

1.4

1.4.0.0 https://github.com/borodulin/yii2-select2

Yii2 Select2 widget

  Sources   Download

MIT

The Requires

 

extension yii2 widget select2

20/08 2015

1.3.1

1.3.1.0 https://github.com/borodulin/yii2-select2

Yii2 Select2 widget

  Sources   Download

MIT

The Requires

 

extension yii2 widget select2

20/08 2015

1.5-beta

1.5.0.0-beta https://github.com/borodulin/yii2-select2

Yii2 Select2 widget

  Sources   Download

MIT

The Requires

 

extension yii2 widget select2

17/08 2015

1.3

1.3.0.0 https://github.com/borodulin/yii2-select2

Yii2 Select2 widget

  Sources   Download

MIT

The Requires

 

extension yii2 widget select2

08/07 2015

1.2

1.2.0.0 https://github.com/borodulin/yii2-select2

Yii2 Select2 widget

  Sources   Download

MIT

The Requires

 

extension yii2 widget select2

08/07 2015

1.1

1.1.0.0 https://github.com/borodulin/yii2-select2

Yii2 Select2 widget

  Sources   Download

MIT

The Requires

 

extension yii2 widget select2