Skip to content

Commit c4da2b3

Browse files
committed
Addition .gitignore and fix type of items
1 parent a90dd7e commit c4da2b3

File tree

2 files changed

+46
-15
lines changed

2 files changed

+46
-15
lines changed

.gitignore

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Created by .ignore support plugin (hsz.mobi)
2+
# phpstorm project files
3+
.idea
4+
# netbeans project files
5+
nbproject
6+
# zend studio for eclipse project files
7+
.buildpath
8+
.project
9+
.settings
10+
# composer itself is not needed
11+
composer.phar
12+
# Mac DS_Store Files
13+
.DS_Store

Selectize.php

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,31 @@
11
<?php
2-
/**
3-
* Created by PhpStorm.
4-
* User: Nghia
5-
* Date: 10/10/2014
6-
* Time: 6:43 AM
7-
*/
8-
92
namespace yii\selectize;
103

11-
124
use yii\helpers\Html;
135
use yii\widgets\InputWidget;
146
use yii\helpers\Json;
157
use yii\jui\JuiAsset;
168

179
class Selectize extends InputWidget
1810
{
19-
public $items = [];
11+
/**
12+
* @var array
13+
*/
14+
public $items;
15+
/**
16+
* @var array
17+
* @see https://github.com/brianreavis/selectize.js/blob/master/docs/usage.md#options
18+
*/
2019
public $clientOptions;
20+
/**
21+
* @var array
22+
* @see https://github.com/brianreavis/selectize.js/blob/master/docs/events.md
23+
*/
2124
public $clientEvents;
2225

26+
/**
27+
* @inheritdoc
28+
*/
2329
public function init()
2430
{
2531
if (!isset($this->options['id'])) {
@@ -34,23 +40,29 @@ public function init()
3440
$this->registerEvents();
3541
}
3642

43+
/**
44+
* @inheritdoc
45+
*/
3746
public function run()
3847
{
3948
if ($this->hasModel()) {
40-
if (empty($this->items)) {
41-
echo Html::activeTextInput($this->model, $this->attribute, $this->options);
42-
} else {
49+
if (is_array($this->items)) {
4350
echo Html::activeDropDownList($this->model, $this->attribute, $this->items, $this->options);
51+
} else {
52+
echo Html::activeTextInput($this->model, $this->attribute, $this->options);
4453
}
4554
} else {
46-
if (empty($this->items)) {
47-
echo Html::textInput($this->name, $this->value, $this->options);
48-
} else {
55+
if (is_array($this->items)) {
4956
echo Html::dropDownList($this->name, $this->value, $this->items, $this->options);
57+
} else {
58+
echo Html::textInput($this->name, $this->value, $this->options);
5059
}
5160
}
5261
}
5362

63+
/**
64+
* Register asset bundles
65+
*/
5466
public function registerAssetBundle()
5567
{
5668
if (isset($this->clientOptions['plugins']) && array_search('drag_drop', $this->clientOptions['plugins'])) {
@@ -61,6 +73,9 @@ public function registerAssetBundle()
6173
SelectizeAsset::register($this->getView());
6274
}
6375

76+
/**
77+
* Register client script
78+
*/
6479
public function registerJs()
6580
{
6681
if (!isset($this->clientOptions['create']) && empty($this->items)) {
@@ -70,6 +85,9 @@ public function registerJs()
7085
$this->getView()->registerJs("jQuery('#{$this->options['id']}').selectize({$clientOptions});");
7186
}
7287

88+
/**
89+
* Register client script handles
90+
*/
7391
public function registerEvents()
7492
{
7593
if (!empty($this->clientEvents)) {

0 commit comments

Comments
 (0)