IvanCloud IvanCloud - 1 month ago 14
PHP Question

yii 2 date picker only allow before today

echo $form->field($model, 'dob')->widget(DatePicker::classname(), [
'options' => [
'placeholder' => Yii::t('app', 'Please pick your birth-date'),
],
'type' => DatePicker::TYPE_INPUT,
'pluginOptions' => [
'autoclose'=>true,
'format' => 'dd/mm/yyyy',
'startView' => 1,
],
])->label(Yii::t('app', 'Date of Birth'));


The code above is used to create a DatePicker in yii 2. Is it possible for me to only allow users to select date before today?

Answer

Yes, you can the future dates disable by endDate property of pluginOptions.

echo $form->field($model, 'dob')->widget(DatePicker::classname(), [
                                'options' => [
                                    'placeholder' => Yii::t('app', 'Please pick your birth-date'), 
                                ],
                                'type' => DatePicker::TYPE_INPUT,
                                'pluginOptions' => [
                                    'autoclose'=>true,
                                    'format' => 'dd/mm/yyyy',
                                    'startView' => 1,
                                    'endDate'=>date('d/m/Y')
                                ],
                            ])->label(Yii::t('app', 'Date of Birth'));
Comments