Mai jos e codul pentru orice tip de selector de data/luna/an bazat pe ActiveForm si Kartik DateControl.
Tot ce trebuie facut e sa setezi variabila $dt.
Sigur ca se mai pot face si alte setari – de exemplu pentru eticheta – de modificat indexul ‘lb’ din $formatVars.
<?php
$dt = 'years'; //one of the 3 indexes below
$formatVars = [
'days' => ['f' => 'Y-m-d', 'df' => '', 'ph' => Yii::t('app', 'select date...'), 'lb' => Yii::t('app', 'On Date')],
'months' => ['f' => 'M Y', 'df' => 'php:M Y', 'ph' => Yii::t('app', 'select month...'), 'lb' => Yii::t('app', 'For Month')],
'years' => ['f' => 'Y', 'df' => 'php:Y', 'ph' => Yii::t('app', 'select year...'), 'lb' => Yii::t('app', 'For Year')],
];
$model->date = date($formatVars[$dt]['f']); // initial value -only for days- or comment to show only the placeholder
echo $form->field($model, 'date', ['template' => '{label}<div class="col-sm-4 prerequisite backgroundOperations">{input}</div>'])
->widget(DateControl::classname(), [
'type' => 'date',
'displayFormat' => $formatVars[$dt]['df'],
'widgetOptions' => [
'type' => 3, //layout type for DatePicker
'options' => ['placeholder' => $formatVars[$dt]['ph']],
'pluginOptions' => [ //DatePicker settings
'todayHighlight' => TRUE,
'minViewMode' => $dt,
],
],
])->label($formatVars[$dt]['lb']);
?>
Categories: Uncategorized |
Leave a Reply
[TOP]