Select2
Searchable Select2 widgets for Yii2 forms
ActiveForm integration, multiple selections, tagging, and paginated AJAX searches
Quick start
Section titled “Quick start”Installation
Section titled “Installation”Configure Foxy native and the asset aliases in the installation guide, then install:
composer require --prefer-dist --prefer-stable php-forge/foxy:^0.4 yii2-extensions/select2:^0.2Dropdown list
Section titled “Dropdown list”use Yii2\Extensions\Select2\Select2;
echo $form ->field($model, 'country') ->widget( Select2::class, [ 'items' => [ 'mx' => 'Mexico', 'ca' => 'Canada', ], 'options' => ['prompt' => ''], 'clientOptions' => [ 'placeholder' => 'Choose a country', 'allowClear' => true, ], ], );Multiple selection and tags
Section titled “Multiple selection and tags”use yii\helpers\Html;use Yii2\Extensions\Select2\Select2;
echo Html::label('Regions', 'regions');echo Select2::widget( [ 'name' => 'regions', 'items' => [ 'north' => 'North', 'south' => 'South', ], 'options' => [ 'id' => 'regions', 'multiple' => true, 'unselect' => '', ], ],);Set clientOptions.tags=true separately to allow new values, and validate them on the server.
The widget uses Select2 4.0 and requires jQuery. Its native asset installation consumes published files without compiling them. See the installation guide for the Yii 22 client-validation adapter and frontend compatibility details.
Documentation
Section titled “Documentation”Practical guides and usage examples for Select2 widgets, forms, and remote searches.
- 📚 Installation Guide: native assets and optional Bootstrap 5 and 6 themes.
- ⚙️ Configuration Guide: models, ActiveForm, accessibility, events, and lifecycle.
- 💡 Usage Examples
- 🔄 Upgrade Guide
- 🧪 Testing Guide
- 🌐 AJAX Searches and Pagination
The guides and the API reference generated from
the PHPDoc in src/ are published at https://yii2-framework.github.io/docs/extensions/select2/.
AI assistance
Section titled “AI assistance”AI agents: read the documentation index and fetch the Markdown version
of a page by appending index.md to its URL. The
AI agents guide covers skill installation, client setup and
verification.
- 🤖
yii2-select2skill: Select2 integration. - 🧭
yii2-frameworkskill: Yii 22.0 application conventions.
The hosted documentation covers Yii 22.0. If it does not match the installed revision or is unavailable, use the repository guides, the skill source, the source PHPDoc and the changelog.
Special thanks
Section titled “Special thanks”This code was initially developed by contributors at yii2-cms and hosted at yii-cms/yii2-select2. We thank them all. For continuity and maintenance we have moved a copy here.
Our social networks
Section titled “Our social networks”Follow on X Follow on Facebook Join our Subreddit Join on Telegram
License
Section titled “License”Package
Section titled “Package”- Source code and issues: yii2-extensions/select2. Star the repository if the package is useful to you.
- Composer package: yii2-extensions/select2.
- Changelog: CHANGELOG.md.