I'm running a datePicker for a date of birth field in Yii2. I'm trying to display the year also. I've checked the JQuery docs http://jqueryui.com/datepicker/#dropdown-month-year and I thought I would be able to achieve this with changeYear
. But it doesn't seem to work. What's the way to do this? 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'
],
]) ?>
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'
],
You can simply use HTML5 date type. That is so simple. You dont need to add widgets:
<?= $form->field($model, 'date_of_birth')->textField(['type' => 'date']);?>
This will add the date picker.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With