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-11-26 16:53:17 UTC


README

Yii Framework

Select2 widget


PHPUnit Coverage Mutation Testing PHPStan

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. Foxy installs published assets without a Node.js build. See the installation guide for the Yii 22 client-validation adapter and frontend compatibility.

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.

  • ๐Ÿค– yii2-select2 skill: Select2 widget installation with Foxy assets, ActiveForm validation of selections and tags, remote data, events, themes and repeatable lifecycle cleanup.
  • ๐Ÿงญ yii2-framework skill: 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.

Package information

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

Project status

PHPStan Level 7 Quality ECS

Security

OpenSSF Scorecard Zizmor

Built with AI

Built with Claude Code Built with Codex Reviewed by CodeRabbit

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