0

Estoy intentando actualizar un campo de texto al seleccionar una fecha en un DatePicker. Lo que quiero lograr es que al fijar una fecha futura en el campo de texto Dias Faltantes se me fijen los dias faltantes para esa fecha. Adjunto el código y una captura de la interfaz desarrolladaintroducir la descripción de la imagen aquí

 <?=
$form->field($model, 'id_proyecto')->widget(Select2::classname(), [
    'data' => ArrayHelper::map(WorkPackages::find()->where('type_id= :type_id', [':type_id' => '17'])
                    ->orWhere('type_id= :type_id', [':type_id' => '18'])
                    ->all(), 'id', 'subject'),
    'language' => 'es',
    'options' => ['placeholder' => 'Seleccione un Proyecto ...'],
    'pluginOptions' => [
        'allowClear' => true
    ],
]);
?>
<?= $form->field($model, 'idtauditoria')->dropDownList(ArrayHelper::map(Tauditoria::find()->all(), 'idtauditoria', 'descripcion')) ?>
<?=
$form->field($model, 'fecha')->widget(DatePicker::className(), [
    'value' => date('d-M-Y', strtotime('+2 days')),
    'options' => ['placeholder' => 'Seleccione ...'],
    'type' => DatePicker::TYPE_COMPONENT_PREPEND,
    'language' => 'es',
    'pluginOptions' => [
        'format' => 'yyyy/mm/dd',
        'autoclose' => true,
        'todayHighlight' => true,
        'orientation' => 'bottom left',
    //  'onSelect' => 'function(dateText,inst){alert("Hello"); }'
    ],
    'pluginEvents' => [
       // 'changeDate' => 'function(e){alert(e); }'
      //  'changeDate' => '$("dfaltantes").val($("fecha option:selected").text());'
    ],
 //  'onchange' => '$("#model-dfaltantes").val($("#model-fecha option:selected").text());'
    ])
?>

<?= $form->field($model, 'idestado')->dropDownList(ArrayHelper::map(Estado::find()->all(), 'idestado', 'descripcion')) ?>

<?= $form->field($model, 'observacion')->textInput(['maxlength' => true]) ?>
<?= $form->field($model, 'dfaltantes')->textInput(['maxlength' => true, 'readonly' => true]) ?>
1
  • Lo he solucionado creando una funcion en JavaScript que fija los dias en el campo de texto al momento de seleccionar la fecha en el kartik DatePicker el 18 jun. 2019 a las 18:39

1 respuesta 1

0

Lo he solucionado creando una funcion en JavaScript que fija los dias en el campo de texto al momento de seleccionar la fecha en el kartik DatePicker. El código de la función lo aniadi en el form y es el siguiente:

<script>
    function calculaDiasFaltantes() { //calcula dias entre la fecha actual y una fecha futura
        var hoy = new Date().getTime();
        var fecAudit = new Date(document.getElementById("fecha").value).getTime();
      //  console.log('fecha_audit '+'soy fec auditoria');
        if (fecAudit >= hoy) {
            var dif = fecAudit - hoy;
            var df = Math.round(dif / (1000 * 60 * 60 * 24));
          //  console.log(df);
           document.getElementById("dfaltantes").value=df;
        }else{
            document.getElementById("dfaltantes").value=0;
          //  console.log('La fecha de auditoría no puede ser menor o igual a la fecha actual');
        }
        return df;
    }
</script>

Tu Respuesta

By clicking “Publica tu respuesta”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

¿No es la respuesta que buscas? Examina otras preguntas con la etiqueta o formula tu propia pregunta.