如何在yii2中选择其他日期选择器时自动填充DatePicker

时间:2016-08-09 04:59:19

标签: yii2

当我选择o_orderdate datepicker时,我正在使用2amigos Datepicker并尝试自动填充o_followup datepicker。这是与Second datepicker is not populating onChange of 1st in yii2相同的问题。请帮忙。 o_orderdate datepicker的代码 -

<?= $form->field($model, 'o_orderdate')->widget(
                    DatePicker::className(), [
                    // inline too, not bad
                     'inline' => false,
                     // modify template for custom rendering
                    //'template' => '<div class="well well-sm" style="background-color: #fff; width:250px">{input}</div>',
                    'clientOptions' => [
                        'autoclose' => true,
                        'todayHighlight' => true,
                        'format' => 'yyyy-mm-dd'
                    ]
                    ]);?>

o_followup datepicker的代码

<?= $form->field($model, 'o_followup')->widget(
                    DatePicker::className(), [
                    // inline too, not bad
                     'inline' => false, 
                     // modify template for custom rendering
                    //'template' => '<div class="well well-sm" style="background-color: #fff; width:250px">{input}</div>',
                    'clientOptions' => [
                        'autoclose' => true,
                        'todayHighlight' => true,
                        'format' => 'yyyy-mm-dd'

                    ]
                    ]);?>

Javascript我试过了 -

<?php
/* start getting the followupdate */
$script = <<<EOD
$(document).ready(function(){
    $("#orders-o_followup").datepicker();
    $("#orders-o_orderdate").datepicker({
        onSelect: function(){
            var fecha = $(this).datepicker('getDate');
            $("#orders-o_followup").datepicker("setDate", new Date(fecha.getTime()));
            $("#orders-o_followup").datepicker("setDate", "+365d");
        }
    });
});
EOD;
$this->registerJs($script);
/*end getting the followupdate */
?>

当我选择o_orderdate datepicker时,根本没有任何事情发生。请帮忙。

部分工作

<?php
/* start getting the followupdate */
$script = <<<EOD
$("#orders-o_orderdate").change(function(){ 
    $("#orders-o_followup").datepicker();
    var fecha = $(this).datepicker('getDate');
            $("#orders-o_followup").datepicker("setDate", new Date(fecha.getTime()));
            $("#orders-o_followup").datepicker("setDate", "+365d");
});
EOD;
$this->registerJs($script);
/*end getting the followupdate */
?>

此代码在o_followup datepicker中填充日期。但是,如果我再次更改o_orderdate,它就不会响应。它仍然停留在初始更改的值。其次,dateformat是“mm / dd / yyyy”。但我想要“yyyy-mm-dd”。请帮忙。

1 个答案:

答案 0 :(得分:0)

试试这个:

$("#orders-o_followup").change(function(){ 
// do do do ;)
});

关于改变做你想要的东西亲爱的)