Reputation: 818
I am using Kartik datepicker in yii2 and I want to disable the previous dates on the calendar to avoid picking them.
Here's my code:
DatePicker::widget([
'model'=>$model,
'attribute'=>'datetime_range',
'name' => 'from_date',
'value' => '01-Feb-1996',
'type' => DatePicker::TYPE_RANGE,
'name2' => 'to_date',
'value2' => '27-Feb-1996',
'pluginOptions' => [
'autoclose'=>true,
'format' => 'dd-M-yyyy',
'todayHighlight' => true,
'startDate' => date("yyyy-MM-dd H:i:s"),
]
]);
Upvotes: 0
Views: 4518
Reputation: 7093
This won't forbid user from picking up passed days, but it will display an error when doing so. What you need to do, is to add an additional rule to rules()
method in model:
[['date'], 'date', 'min' => time(), 'minString' => date('d-m-Y'), 'format' => 'php:d-m-Y']
The first word date
is your attribute (probably from_date
?).
Upvotes: 0