Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

188
Views
Empty load date whrn trying yo update - Yii2

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()'),
                              ]
                        ]
                    ) ?>
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

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,
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!