It happens that I have used the minDate option to deactivate the days before the current one to avoid selecting a date already in the past. This works perfectly for me in the create but in the update it does not show me the time, only the empty widget appears, although in the database it shows that the date was registered. I would like to know what error may be happening.
Rules
[['inicio_clase', 'fin_clase'], 'default', 'value' => function () {
return date(DATE_ISO8601);
}],
[['inicio_clase', 'fin_clase'], 'filter', 'filter' => 'strtotime', 'skipOnEmpty' => true],
[['inicio_clase', 'fin_clase','seccion_id', 'materia_id', 'estado'], 'integer'],
['inicio_clase','compare','compareAttribute'=>'fin_clase','operator'=>'<','message'=>'La fecha de inicio debe ser menor que la fecha de finalización.'],
['fin_clase','compare','compareAttribute'=>'inicio_clase','operator'=>'>','message'=>'La fecha de fin no debe ser menor o igual que la fecha de inicio.'],
Form
<?php echo $form->field($model, 'fin_clase'(
DateTimeWidget::class,
[
'phpDatetimeFormat' => 'yyyy/MM/dd HH:mm',
'clientOptions' => [
'minDate' => new \yii\web\JsExpression('new Date()'),
]
]
) ?>
You are probably trying to edit record with fin_clase set to the date before current date. The DateTimeWidget is set to not allow the date before the current day so it won't be able to show date in past even if that value is stored in model.
For example if today is 2021-10-12 and the record's fin_clase is set to 2021-10-11 it won't be filled during edit.
To avoid that you should set minDate to allow the actual value stored in model.
'minDate' => $model->isNewRecord
? new \yii\web\JsExpression('new Date()')
: new \yii\web\JsExpression("new Date({$model->fin_clase})"),
Or you might want to allow all dates in past when editing record.
'minDate' => $model->isNewRecord
? new \yii\web\JsExpression('new Date()')
: false,