1
1
<?php
2
- /**
3
- * Created by PhpStorm.
4
- * User: Nghia
5
- * Date: 10/10/2014
6
- * Time: 6:43 AM
7
- */
8
-
9
2
namespace yii \selectize ;
10
3
11
-
12
4
use yii \helpers \Html ;
13
5
use yii \widgets \InputWidget ;
14
6
use yii \helpers \Json ;
15
7
use yii \jui \JuiAsset ;
16
8
17
9
class Selectize extends InputWidget
18
10
{
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
+ */
20
19
public $ clientOptions ;
20
+ /**
21
+ * @var array
22
+ * @see https://github.com/brianreavis/selectize.js/blob/master/docs/events.md
23
+ */
21
24
public $ clientEvents ;
22
25
26
+ /**
27
+ * @inheritdoc
28
+ */
23
29
public function init ()
24
30
{
25
31
if (!isset ($ this ->options ['id ' ])) {
@@ -34,23 +40,29 @@ public function init()
34
40
$ this ->registerEvents ();
35
41
}
36
42
43
+ /**
44
+ * @inheritdoc
45
+ */
37
46
public function run ()
38
47
{
39
48
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 )) {
43
50
echo Html::activeDropDownList ($ this ->model , $ this ->attribute , $ this ->items , $ this ->options );
51
+ } else {
52
+ echo Html::activeTextInput ($ this ->model , $ this ->attribute , $ this ->options );
44
53
}
45
54
} else {
46
- if (empty ($ this ->items )) {
47
- echo Html::textInput ($ this ->name , $ this ->value , $ this ->options );
48
- } else {
55
+ if (is_array ($ this ->items )) {
49
56
echo Html::dropDownList ($ this ->name , $ this ->value , $ this ->items , $ this ->options );
57
+ } else {
58
+ echo Html::textInput ($ this ->name , $ this ->value , $ this ->options );
50
59
}
51
60
}
52
61
}
53
62
63
+ /**
64
+ * Register asset bundles
65
+ */
54
66
public function registerAssetBundle ()
55
67
{
56
68
if (isset ($ this ->clientOptions ['plugins ' ]) && array_search ('drag_drop ' , $ this ->clientOptions ['plugins ' ])) {
@@ -61,6 +73,9 @@ public function registerAssetBundle()
61
73
SelectizeAsset::register ($ this ->getView ());
62
74
}
63
75
76
+ /**
77
+ * Register client script
78
+ */
64
79
public function registerJs ()
65
80
{
66
81
if (!isset ($ this ->clientOptions ['create ' ]) && empty ($ this ->items )) {
@@ -70,6 +85,9 @@ public function registerJs()
70
85
$ this ->getView ()->registerJs ("jQuery('# {$ this ->options ['id ' ]}').selectize( {$ clientOptions }); " );
71
86
}
72
87
88
+ /**
89
+ * Register client script handles
90
+ */
73
91
public function registerEvents ()
74
92
{
75
93
if (!empty ($ this ->clientEvents )) {
0 commit comments