编程语言
首页 > 编程语言> > PHP-如何在Yii的CJuiDatepicker中单击日历后填充其他值

PHP-如何在Yii的CJuiDatepicker中单击日历后填充其他值

作者:互联网

单击日历日期后,我无法设置结帐日期的值.这是代码.我尝试通过给定函数onSelect填充check_out_date的值,但是目标输入值没有任何变化.谁能帮助我提供解决方案?

这是一段代码:

    <div class="row">
<?php
        echo $form->labelEx($model, 'check_in_date');
        //echo $form->textField($model,'check_in_date');
        $this->widget('zii.widgets.jui.CJuiDatePicker', array(
            'name' => 'Reservation[check_in_date]',
            'value' => ($model->check_in_date) ?
                $model->check_in_date :
                date('m/d/Y'),
            'options' => array(
                'dateFormat' => 'mm/dd/yy',
                'disabled' => 'true',
                'showAnim' => 'fold',
                //'beforeShowDay' => 'js:$.datepicker.noWeekends',
                'onSelect' => 
                    'js:function() {
                        // to automatically assign check out date input value
                        $("#Reservation_check_out_date").val("04/23/2011");
                    }',
                'minDate' => '0',
                'changeMonth' => true,
                'changeYear' => true,
            ),
            'htmlOptions' => array(
                'style' => 'height:20px;'
            ),
        )
    );

    echo $form->error($model, 'check_in_date');
?>
    </div>
    <div class="row">
<?php
        echo $form->labelEx($model, 'check_out_date');
        //echo $form->textField($model, 'check_out_date');
        $this->widget('zii.widgets.jui.CJuiDatePicker', array(
/*
            'model'=>$model,
            'attribute' => 'check_out_date',
*/
            'name' => 'Resevation[check_out_date]',
            'value' => ($model->check_out_date) ?
                $model->check_in_date :
                date('m/d/Y', strtotime("+1 day")),
            'options' => array(
                'dateFormat' => 'mm/dd/yy',
                'showAnim' => 'fade',  
                'changeMonth' => true,
                'changeYear' => true,
                'showOn' => 'button',
                'buttonImage' => Yii::app()->request->baseUrl . '/images/calendar.png',
                'buttonImageOnly' => true,
                'beforeShow' =>
                    'js:function() {
                        var selectedDate = $("#' . CHtml::activeId($model, 'check_in_date') . '").datepicker("getDate");
                        selectedDate.setDate(selectedDate.getDate() + 1);
                        $(this).datepicker("option", "minDate", selectedDate);
                    }'
            ),
            'htmlOptions' => array(
                'style' => 'font-size:0.8em',
                'disabled' => 'disabled',
            ),
        )
    );

    echo $form->error($model, 'check_out_date');
?>
    </div>

解决方法:

您可以在’onSelect’事件中获取选定日期,并在function()上添加一个参数,如下所示:

'onSelect'=> 'js:function( selectedDate ) {}

并将此日期应用于其他datePicker,您可以通过以下方式进行操作:

    'onSelect'=> 'js:function( selectedDate ) {
                  $("#'.CHtml::activeId($model,'check_out_date').'").datepicker( "option", "minDate", selectedDate );
    }',

标签:jquery-ui,yii,php,zii-widgets
来源: https://codeday.me/bug/20191208/2091836.html