# Selectize

> Selectize selects and text inputs for Yii models and forms

**Selectize selects and text inputs for Yii models and forms**

_Bootstrap 5 styling, multiple values, remote JSON choices and lifecycle cleanup_

## Quick start

### Installation

Configure the consuming application's plugins and asset aliases with the [installation guide](/docs/extensions/selectize/installation/index.md),
then install the documented branch:

```shell
composer require --prefer-dist yii2-extensions/selectize:^0.2
```

The native asset manager installs the published frontend assets without Node.js or a JavaScript build. Keep an existing
application manager when it already supplies those assets.

### Basic usage

Place this in a Yii view and associate the input with a visible label:

```php
use yii\helpers\Html;
use yii2\extensions\selectize\Selectize;

echo Html::label('Category', 'category');
echo Selectize::widget(
    [
        'name' => 'category',
        'value' => 'yii',
        'items' => ['php' => 'PHP', 'yii' => 'Yii'],
        'options' => ['id' => 'category', 'prompt' => 'Choose a category'],
        'clientOptions' => ['maxItems' => 1],
    ],
);
```

Item keys are submitted values. To bind a model attribute in an ActiveForm:

```php
use yii2\extensions\selectize\Selectize;

echo $form->field($model, 'tags')
    ->widget(
        Selectize::class,
        [
            'items' => ['php' => 'PHP', 'yii' => 'Yii'],
            'options' => ['multiple' => true],
            'clientOptions' => ['plugins' => ['remove_button']],
        ],
    );
```

The model must validate `tags` as an array; browser options do not authorize submitted values. See
[model validation](/docs/extensions/selectize/configuration/index.md#model-validation-and-multiple-values) for cleared fields and rejected
submissions.

## Documentation

Practical guides and examples for widget configuration, forms and remote choices.

- 📚 [Installation Guide](/docs/extensions/selectize/installation/index.md): packages, managers and asset aliases.
- ⚙️ [Configuration Guide](/docs/extensions/selectize/configuration/index.md): model values, remote data and rendering.
- 💡 [Usage Examples](/docs/extensions/selectize/examples/index.md): validated, multiple, text and remote fields.
- 🔁 [Events, Accessibility and Lifecycle](/docs/extensions/selectize/lifecycle/index.md)
- 🔄 [Upgrade Guide](https://github.com/yii2-extensions/selectize/blob/main/UPGRADE.md)
- 🧪 [Testing Guide](/docs/extensions/selectize/testing/index.md)

The guides and the [API reference](https://yii2-framework.github.io/docs/extensions/selectize/reference/) generated from
the PHPDoc in `src/` are published at <https://yii2-framework.github.io/docs/extensions/selectize/>.

## AI assistance

AI agents: read the [documentation index](https://yii2-framework.github.io/docs/llms.txt) and fetch the Markdown version
of a page by appending `index.md` to its URL. The
[AI agents guide](https://yii2-framework.github.io/docs/project/ai-agents/) covers skill installation, client setup and
verification.

- 🤖 [`yii2-selectize` skill](/docs/extensions/selectize/agents/index.md): Selectize widgets.
- 🧭 [`yii2-framework` skill](https://yii2-framework.github.io/docs/guide/skills/yii2-framework/): 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](#documentation), the [skill source](https://github.com/yii2-extensions/selectize/blob/main/skills/yii2-selectize/SKILL.md), the source PHPDoc and the
[changelog](https://github.com/yii2-extensions/selectize/blob/main/CHANGELOG.md).

## Our social networks

[Follow on X](https://x.com/Terabytesoftw)
[Follow on Facebook](https://www.facebook.com/wilmer.arambula.9)
[Join our Subreddit](https://www.reddit.com/r/Yii2/)
[Join on Telegram](https://t.me/yii_framework_in_english)

## License

[License](https://github.com/yii2-extensions/selectize/blob/main/LICENSE)

The extension uses [BSD-3-Clause](https://github.com/yii2-extensions/selectize/blob/main/LICENSE). Bundled third-party JavaScript retains its Apache-2.0 and MIT terms; see the
[third-party runtime notices](https://github.com/yii2-extensions/selectize/blob/main/src/asset/js/selectize/NOTICE.md).

## Package

- Source code and issues: [yii2-extensions/selectize](https://github.com/yii2-extensions/selectize). Star the repository if the package is useful to you.
- Composer package: [yii2-extensions/selectize](https://packagist.org/packages/yii2-extensions/selectize).
- Changelog: [CHANGELOG.md](https://github.com/yii2-extensions/selectize/blob/main/CHANGELOG.md).