Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

183
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda