Yii2 DatePicker

I am running datePicker for the date of birth of a field in Yii2. I'm also trying to show the year. I checked the jQuery docs http://jqueryui.com/datepicker/#dropdown-month-year and I thought I could achieve this with changeYear . But it doesn't seem to work. How to do it? This is my current code.

 <?= $form->field($model, 'date_of_birth')->widget(DatePicker::className(),[ 'name' => 'date_of_birth', 'language' => 'en-GB', 'dateFormat' => 'yyyy-MM-dd', 'options' => [ 'changeMonth' => true, 'changeYear' => true, 'yearRange' => '1996:2099', 'showOn' => 'button', 'buttonImage' => 'images/calendar.gif', 'buttonImageOnly' => true, 'buttonText' => 'Select date' ], ]) ?> 
+5
source share
3 answers

You should simply use clientOptions instead of options :

 'clientOptions' => [ 'changeMonth' => true, 'yearRange' => '1996:2099', 'changeYear' => true, 'showOn' => 'button', 'buttonImage' => 'images/calendar.gif', 'buttonImageOnly' => true, 'buttonText' => 'Select date' ], 
+14
source

You can simply use the HTML5 date type. It is so simple. You do not need to add widgets:

 <?= $form->field($model, 'date_of_birth')->textField(['type' => 'date']);?> 

This will add a date picker.

+7
source

You can use the following codes:

  use yii\helpers\Html; use yii\widgets\ActiveForm; use kartik\select2\Select2; use yii\helpers\ArrayHelper; use kartik\date\DatePicker; use yii\widgets\Pjax; <?=$form->field($model, 'columnName')->widget(DatePicker::classname(), [ 'language' => 'tr', 'value' => date('dd/mm/yyyy', strtotime('+7 days')), 'readonly' => true, #'disabled' => true, #'size' => 'lg', #'type' => DatePicker::TYPE_COMPONENT_APPEND, 'options' => ['placeholder' => 'Başlangıç Tarihi Seç ...'], 'pluginOptions' => [ #'orientation' => 'top right', 'format' => 'dd/mm/yyyy', 'todayHighlight' => true, 'todayBtn' => true, 'autoclose'=>true, ] ]);?> 
0
source

Source: https://habr.com/ru/post/1211844/


All Articles