Yii2 jui datepicker范围不起作用

时间:2016-04-10 08:10:10

标签: jquery datepicker yii2

我想在我看来从 - 进入日期。以下是代码。我希望'date_to'日期选择器从'date_from'选择的日期开始。但这不会发生。 'date_to'日期选择器从今天开始。

    <?php
use yii\helpers\Html;
use yii\widgets\ActiveForm;
use yii\helpers\Url;
use yii\helpers\ArrayHelper;
use yii\jui\DatePicker;
use common\models\Room;
use common\models\Customer;


/* @var $this yii\web\View */
/* @var $model common\models\Reservation */

$this->title = 'Create Reservation';
$this->params['breadcrumbs'][] = ['label' => 'Reservations', 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
?>

<?php $form = ActiveForm::begin(); ?> 
<div class="row">
    <div class="col-lg-12">
        <h1>Create Reservation form</h1>
        <?= $form->field($model, 'room_id')->dropDownList($this->params['itemRooms'],[ 'prompt' => '--- choose from ---' ]) ?>
        <?= $form->field($model, 'customer_id')->dropDownList($this->params['itemCustomers'],[ 'prompt' => '--- choose from ---' ]) ?>
        <?= $form->field($model, 'price_per_day')->textInput() ?>
        <?= $form->field($model, 'date_from')->widget(\yii\jui\DatePicker::classname(), [
                'clientOptions' => 
                    [
                        'numberOfMonths' => 3,
                        "changeMonth" => true,
                        'onClose' => new \yii\web\JsExpression('function( getDate ) {
                                        $( "#reservation-date_to" ).datepicker( "clientOptions", "minDate", getDate );
                                    }'),
                    ],
        ])  ?>
        <?= $form->field($model, 'date_to')->widget(\yii\jui\DatePicker::classname(), [
                'clientOptions' => 
                    [
                        'numberOfMonths' => 3,
                        "changeMonth" => true,
                        'onClose' =>  new \yii\web\JsExpression('function( getDate ) {
                                        $( "#reservation-date_from" ).datepicker( "clientOptions", "maxDate", getDate );
                                    }'),
                    ],

        ])  ?>
   </div>
</div>
<div class="form-group">
    <?= Html::submitButton('Create' , ['class' => 'btn btn-success']) ?>
</div>
<?php ActiveForm::end(); ?>

1 个答案:

答案 0 :(得分:1)

您可以尝试使用option代替clientOptions

例如,

<?= $form->field($model, 'date_from')->widget(yii\jui\DatePicker::className(), [
            'clientOptions' =>[
                'numberOfMonths' => 3,
                'minDate' => '+1m +1w',
                'changeMonth' => true,
                'onClose' => new \yii\web\JsExpression('function( selectedDate ) {
                    $( "#'.Html::getInputId($model, 'date_to').'" ).datepicker( "option", "minDate", selectedDate ); 
                }'),
            ],

        ]) ?>