yii2-extensions / select2
select2 widget for Yii Framework 2
0.1
2024-09-29 14:23 UTC
Requires
- php: >=8.1
- npm-asset/select2: ^4.0.13
- npm-asset/select2-bootstrap-5-theme: ^1.3.0
- yii2-extensions/asset-bootstrap5: ^0.1
- yiisoft/yii2: ^2.0.49 || ^2.2
Requires (Dev)
- maglnet/composer-require-checker: ^4.7
- php-forge/support: ^0.1
- phpunit/phpunit: ^10.5
- roave/infection-static-analysis-plugin: ^1.34
- symplify/easy-coding-standard: ^12.1
- yii2-extensions/phpstan: ^0.1
This package is auto-updated.
Last update: 2024-10-29 14:51:07 UTC
README
Select2 widget for Yii2 framework
Installation
The preferred way to install this extension is through composer.
Either run
composer require --prefer-dist yii2-extensions/select2:^0.1
or add
"yii2-extensions/select2": "^0.1"
to the require section of your composer.json
file.
Usage
Dropdown list
use Yii2\Extension\Select2\Select2; <?= $form->field($model, 'user_id')->widget(Select2::className(), [ 'items' => ArrayHelper::map(User::find()->all(), 'id', function($model) { return $model->username . " <{$model->email}>"; }), 'clientOptions' => [ 'placeholder' => 'User', 'allowClear' => true, ], 'clientEvents' => [ 'change'=>'function (e) { console.log("Select2 change."); }', ], ]) ?>
Multiple aka Tag mode input
use Yii2\Extension\Select2\Select2; <?= Select2::widget([ 'name' => 'InputName', 'items' => ArrayHelper::map(User::find()->all(), 'id', function($model) { return $model->fio . " <{$model->email}>"; }), 'options' => [ 'multiple' => true, ] 'clientOptions' => [ 'placeholder' => 'User', 'allowClear' => true, ] ]) ?>
Properties of the widget
For more details see: https://github.com/select2/select2
Special Thanks
This code was initially developed by contributors at yii2-cms and hosted at repo: https://github.com/yii-cms/yii2-select2. We thank them all. For continuity and maintenance we have moved a copy here.
Quality code
Support versions Yii2
Testing
Check the documentation testing to learn about testing.
Our social networks
License
The MIT License. Please see License File for more information.