Search by

Select2 widgets for Yii2 with ActiveForm, AJAX searches, and native browser assets.

0.2.1 2026-10-23 10:01 UTC

This package is auto-updated.

Last update: 2026-10-23 10:05:59 UTC


README

Yii Framework

Select2 widget


PHPUnit Mutation Testing PHPStan Security

Searchable Select2 widgets for Yii2 forms
ActiveForm integration, multiple selections, tagging, and paginated AJAX searches

Quick start

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.2

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

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

Practical guides and usage examples for Select2 widgets, forms, and remote searches.

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

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.

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.

Package information

PHP Yii 2.0.55+ Yii 22.0.x Latest Stable Version Total Downloads

Project status

Codecov PHPStan Level 7 Quality ECS

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

Follow on X Follow on Facebook Join our Subreddit Join on Telegram

License

License