@@ -58,6 +58,17 @@ class DatePicker extends \kartik\base\InputWidget
58
58
* - 'label': string the button label. Defaults to `<i class="glyphicon glyphicon-calendar"></i>`
59
59
*/
60
60
public $ buttonOptions = [];
61
+
62
+ /**
63
+ * @var mixed the calendar picker button configuration.
64
+ * - if this is passed as a string, it will be displayed as is (will not be HTML encoded).
65
+ * - if this is set to false, the picker button will not be displayed.
66
+ * - if this is passed as an array (this is the DEFAULT) it will treat this as HTML attributes
67
+ * for the button (to be displayed as a Bootstrap addon). The following special keys are recognized;
68
+ * - icon - string, the bootstrap glyphicon name/suffix. Defaults to 'calendar'.
69
+ * - title - string, the title to be displayed on hover. Defaults to 'Select date & time'.
70
+ */
71
+ public $ pickerButton = [];
61
72
62
73
/**
63
74
* @var mixed the calendar remove button configuration - applicable only for type
@@ -135,6 +146,7 @@ class DatePicker extends \kartik\base\InputWidget
135
146
*/
136
147
public function init ()
137
148
{
149
+ $ this ->_msgCat = 'kvdate ' ;
138
150
parent ::init ();
139
151
$ this ->_hasAddon = $ this ->type == self ::TYPE_COMPONENT_PREPEND || $ this ->type == self ::TYPE_COMPONENT_APPEND ;
140
152
if ($ this ->type === self ::TYPE_RANGE && $ this ->attribute2 === null && $ this ->name2 === null ) {
@@ -156,6 +168,7 @@ public function init()
156
168
throw new InvalidConfigException ("The 'attribute2' property must be set for a 'range' type markup and a defined 'form' property. " );
157
169
}
158
170
$ s = DIRECTORY_SEPARATOR ;
171
+ $ this ->initI18N ();
159
172
$ this ->setLanguage ('bootstrap-datepicker. ' , __DIR__ . "{$ s }assets {$ s }" , null , '.min.js ' );
160
173
$ this ->parseDateFormat ('date ' );
161
174
$ this ->_id = ($ this ->type == self ::TYPE_INPUT ) ? 'jQuery("# ' . $ this ->options ['id ' ] . '") ' : 'jQuery("# ' . $ this ->options ['id ' ] . '").parent() ' ;
@@ -191,21 +204,30 @@ protected function renderInput()
191
204
}
192
205
193
206
/**
194
- * Returns the remove button addon
207
+ * Returns the addon to render
208
+ *
209
+ * @param array $options the HTML attributes for the addon
210
+ * @param string $type whether the addon is the picker or remove
195
211
* @return string
196
212
*/
197
- protected function renderRemoveButton ( )
213
+ protected function renderAddon (& $ options , $ type = ' picker ' )
198
214
{
199
- $ options = $ this ->removeButton ;
200
215
if ($ options === false ) {
201
216
return '' ;
202
217
}
203
- Html::addCssClass ($ options , 'input-group-addon kv-date-remove ' );
204
- $ icon = '<i class="glyphicon glyphicon- ' . ArrayHelper::remove ($ options , 'icon ' , 'remove ' ) . '"></i> ' ;
218
+ if (is_string ($ options )) {
219
+ return $ options ;
220
+ }
221
+ $ icon = ($ type === 'picker ' ) ? 'calendar ' : 'remove ' ;
222
+ Html::addCssClass ($ options , 'input-group-addon kv-date- ' . $ icon );
223
+ $ icon = '<i class="glyphicon glyphicon- ' . ArrayHelper::remove ($ options , 'icon ' , $ icon ) . '"></i> ' ;
205
224
if (empty ($ options ['title ' ])) {
206
- $ options ['title ' ] = Yii::t ('app ' , 'Clear field ' );
225
+ $ title = ($ type === 'picker ' ) ? Yii::t ('kvdate ' , 'Select date ' ) : Yii::t ('kvdate ' , 'Clear field ' );
226
+ if ($ title != false ) {
227
+ $ options ['title ' ] = $ title ;
228
+ }
207
229
}
208
- return Html::tag ('span ' , $ icon , $ options );
230
+ return Html::tag ('span ' , $ icon , $ options );
209
231
}
210
232
211
233
/**
@@ -231,11 +253,11 @@ protected function parseMarkup($input)
231
253
}
232
254
if ($ this ->_hasAddon ) {
233
255
Html::addCssClass ($ this ->_container , 'date ' );
234
- $ addon = " <span class='input-group-addon'> { $ this ->addon } </span> " ;
235
- $ remove = $ this ->renderRemoveButton ( );
236
- $ content = $ addon . $ remove . $ input ;
256
+ $ picker = $ this -> renderAddon ( $ this ->pickerButton ) ;
257
+ $ remove = $ this ->renderAddon ( $ this -> removeButton , ' remove ' );
258
+ $ content = $ picker . $ remove . $ input ;
237
259
if ($ this ->type == self ::TYPE_COMPONENT_APPEND ) {
238
- $ content = $ input . $ remove . $ addon ;
260
+ $ content = $ input . $ remove . $ picker ;
239
261
}
240
262
return Html::tag ('div ' , $ content , $ this ->_container );
241
263
}
0 commit comments