3

单击日历日期后,我在设置结帐日期的值时遇到问题。这是代码。我尝试check_out_date通过给函数填充值onSelect,但目标输入值没有任何变化。任何人都可以帮我提供解决方案吗?

这是一段代码:

    <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>
4

2 回答 2

2

您可以在 'onSelect' 事件中使用选定日期,并在 function() 上使用参数,如下所示:

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

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

    'onSelect'=> 'js:function( selectedDate ) {
                  $("#'.CHtml::activeId($model,'check_out_date').'").datepicker( "option", "minDate", selectedDate );
    }',
于 2013-07-31T12:51:59.550 回答
1

你能试一下吗:

'onSelect' => 'js:function() {$("#Reservation_check_out_date").setDate("04/23/2011");}',

jQuery UI 文档:http: //jqueryui.com/demos/datepicker/#method-setDate

于 2012-03-26T17:48:10.073 回答