@@ -30,24 +30,28 @@ class Widget extends InputWidget
3030
3131 /**
3232 * Disable input
33+ *
3334 * @var bool
3435 */
3536 public $ disabled = false ;
3637
3738 /**
3839 * Show group buttons
40+ *
3941 * @var bool
4042 */
4143 public $ groupBtnShow = false ;
4244
4345 /**
4446 * Buttons template
47+ *
4548 * @var string
4649 */
47- public $ groupBtnTemplate = '{toggle}{clear} ' ;
50+ public $ groupBtnTemplate = '{toggle} {clear} ' ;
4851
4952 /**
5053 * Buttons
54+ *
5155 * @var array
5256 */
5357 public $ groupBtn = [
@@ -79,99 +83,105 @@ public function init()
7983 */
8084 public function run ()
8185 {
82- if ($ this ->groupBtnShow )
86+ if ($ this ->groupBtnShow ) {
8387 $ this ->clientOptions ['wrap ' ] = true ;
84- else
88+ } else {
8589 $ this ->clientOptions ['wrap ' ] = false ;
90+ }
8691
8792 $ this ->registerClientScript ();
8893 $ content = '' ;
8994 $ options ['data-input ' ] = '' ;
90- if ($ this ->disabled )
95+ if ($ this ->disabled ) {
9196 $ options ['disabled ' ] = 'disabled ' ;
97+ }
9298
9399 if ($ this ->groupBtnShow ) {
94100 $ content .= '<div class="flatpickr- ' . $ this ->options ['id ' ] . ' input-group"> ' ;
95101
96102 if ($ this ->hasModel ()) {
97- $ content .= Html::activeTextInput ($ this ->model , $ this ->attribute , array_merge ($ this ->options , $ options ));
103+ $ content .= Html::activeTextInput ($ this ->model , $ this ->attribute , ArrayHelper:: merge ($ this ->options , $ options ));
98104 } else {
99- $ content .= Html::textInput ($ this ->name , $ this ->value , array_merge ($ this ->options , $ options ));
105+ $ content .= Html::textInput ($ this ->name , $ this ->value , ArrayHelper:: merge ($ this ->options , $ options ));
100106 }
101107
102108 $ content .= '<div class="input-group-btn"> ' ;
103109 if (preg_match_all ('/{(toggle|clear)}/i ' , $ this ->groupBtnTemplate , $ matches )) {
104- foreach ($ matches [1 ] as $ btnName )
110+ foreach ($ matches [1 ] as $ btnName ) {
105111 $ content .= $ this ->renderGroupBtn ($ btnName );
112+ }
106113 }
107114 $ content .= '</div> ' ;
108115 $ content .= '</div> ' ;
109116 } else {
110117 if ($ this ->hasModel ()) {
111- $ content = Html::activeTextInput ($ this ->model , $ this ->attribute , array_merge ($ this ->options , $ options ));
118+ $ content = Html::activeTextInput ($ this ->model , $ this ->attribute , ArrayHelper:: merge ($ this ->options , $ options ));
112119 } else {
113- $ content = Html::textInput ($ this ->name , $ this ->value , array_merge ($ this ->options , $ options ));
120+ $ content = Html::textInput ($ this ->name , $ this ->value , ArrayHelper:: merge ($ this ->options , $ options ));
114121 }
115122 }
116123
117124 return $ content ;
118125 }
119126
120- /**
127+ /**
121128 * Register widget client scripts.
122129 */
123130 protected function registerClientScript ()
124131 {
125132 $ view = $ this ->getView ();
126133
127- if ($ this ->groupBtnShow )
134+ if ($ this ->groupBtnShow ) {
128135 $ selector = Json::encode ('.flatpickr- ' . $ this ->options ['id ' ]);
129- else
136+ } else {
130137 $ selector = Json::encode ('# ' . $ this ->options ['id ' ]);
138+ }
131139
132140 $ options = !empty ($ this ->clientOptions ) ? Json::encode ($ this ->clientOptions ) : '' ;
133141
134142 FlatpickrAsset::register ($ view );
135143 if (!empty ($ this ->theme )) {
136144 FlatpickrAsset::register ($ view )->css [] = 'themes/ ' . $ this ->theme . '.css ' ;
137145 }
138- if (! empty ( $ this ->locale ) ) {
146+ if ($ this -> locale !== null && $ this ->locale !== ' en ' ) {
139147 FlatpickrAsset::register ($ view )->js [] = 'l10n/ ' . $ this ->locale . '.js ' ;
140148 }
141149
142150 $ view ->registerJs ("flatpickr( $ selector, {$ options }); " );
143151 }
144-
145-
146-
147- /**
152+
153+ /**
148154 * @param string $btnName
149155 * @return string
150156 */
151157 private function renderGroupBtn ($ btnName )
152158 {
153159 $ content = '' ;
154160 if (isset ($ this ->groupBtn [$ btnName ])) {
155- if (isset ($ this ->groupBtn [$ btnName ]['btnClass ' ]))
161+ if (isset ($ this ->groupBtn [$ btnName ]['btnClass ' ])) {
156162 $ btnClass = $ this ->groupBtn [$ btnName ]['btnClass ' ];
157- else
163+ } else {
158164 $ btnClass = 'btn btn-default ' ;
165+ }
159166
160- if (isset ($ this ->groupBtn [$ btnName ]['iconClass ' ]))
167+ if (isset ($ this ->groupBtn [$ btnName ]['iconClass ' ])) {
161168 $ iconClass = $ this ->groupBtn [$ btnName ]['iconClass ' ];
162- else
169+ } else {
163170 $ iconClass = '' ;
171+ }
164172
165173 $ disabled = '' ;
166- if ($ this ->disabled )
174+ if ($ this ->disabled ) {
167175 $ disabled = 'disabled="disabled" ' ;
176+ }
168177
169178 $ content = <<<HTML
170179 <button class=" $ btnClass" type="button" $ disabled data- $ btnName>
171180 <span class=" $ iconClass"></span>
172181 </button>
173182HTML ;
174183 }
184+
175185 return $ content ;
176186 }
177187}
0 commit comments