https://github.com/ommu/yii2-selectize
selectize.js wrapper for Yii2 framework.
https://github.com/ommu/yii2-selectize
dropdown form selectize selectizejs tag-input tags yii2 yii2-extension
Last synced: 5 months ago
JSON representation
selectize.js wrapper for Yii2 framework.
- Host: GitHub
- URL: https://github.com/ommu/yii2-selectize
- Owner: ommu
- License: mit
- Fork: true (yii2mod/yii2-selectize)
- Created: 2019-04-29T05:23:48.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2025-08-05T02:01:32.000Z (7 months ago)
- Last Synced: 2025-09-07T13:04:41.948Z (6 months ago)
- Topics: dropdown, form, selectize, selectizejs, tag-input, tags, yii2, yii2-extension
- Language: PHP
- Homepage:
- Size: 48.8 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
Yii2 Selectize Widget
Widget based on selectize.js extension https://selectize.github.io/selectize.js/
[](https://packagist.org/packages/yii2mod/yii2-selectize) [](https://packagist.org/packages/yii2mod/yii2-selectize) [](https://packagist.org/packages/yii2mod/yii2-selectize)
[](https://travis-ci.org/yii2mod/yii2-selectize)
Installation
------------
The preferred way to install this extension is through [composer](http://getcomposer.org/download/).
Either run
```
php composer.phar require --prefer-dist ommu/yii2-selectize "dev-master"
```
or add
```json
"ommu/yii2-selectize": "dev-master"
```
to the require section of your composer.json.
Usage
------------
Once the extension is installed, simply add widget to your page as follows:
1) Tagging input:
```php
echo $form->field($model, "attribute")->widget(Selectize::className(), [
'pluginOptions' => [
'persist' => false,
'createOnBlur' => true,
'create' => true
]
]);
```
2) Select input:
```php
echo $form->field($model, "attribute")->widget(Selectize::className(), [
'items' => [
'Yes',
'No'
],
'pluginOptions' => [
'persist' => false,
'createOnBlur' => true,
'create' => true
]
]);
```
3) Tagging input with remote source and default values(If you want render select input, just setup items property):
**Setup view file:**
```php
// setup the following to get the existing data from database
$model->attribute = 'first, last';
// or if the data is an array you can preselect the tags like this
$model->attribute = implode(', ', ["first", "last"]);
echo $form->field($model, "attribute")->widget(Selectize::className(), [
'url' => '/site/search',
'pluginOptions' => [
'valueField' => 'name',
'labelField' => 'name',
'searchField' => ['name'],
'persist' => false,
'createOnBlur' => true,
'create' => true
]
]);
```
**Your action must return data in the json format, for example:**
```php
public function actionSearch($query = null)
{
Yii::$app->response->format = Response::FORMAT_JSON;
return [
['name' => 'Search Item 1'],
['name' => 'Search Item 2'],
];
}
```
4) Usage widget with plugins:
```php
echo Selectize::widget([
'name' => 'tag-selectize',
'options' => [
'data-data' => $values ? Json::encode($values) : null // Set default values
],
'pluginOptions' => [
// define list of plugins
'plugins' => ['drag_drop', 'remove_button'],
'persist' => false,
'createOnBlur' => true,
'create' => true
]
]);
```
Select Options
----------------
You can find them on the [options page](https://github.com/brianreavis/selectize.js/blob/master/docs/api.md)