yii2 datepicker显示开始日期大于当前日期

时间:2016-07-28 18:05:37

标签: yii2 yii2-advanced-app

我想显示大于当前日期的日期 在ValidFrom中,在ValidUpto字段中的日期大于ValidFrom但无法显示。我想在日期选择器中隐藏以前的日期。

我的代码如下。

 echo DatePicker::widget([
        'model' => $model,
        'attribute' => 'ValidFrom',
        'attribute2' => 'ValidUpto',
        'options' => ['placeholder' => 'valid from',

        ],
        'options2' => ['placeholder' => 'valid to'],
        'type' => DatePicker::TYPE_RANGE,
        'form' => $form,

        'pluginOptions' => [
            'format' => 'yyyy-mm-dd',
            'autoclose' => true,
        ],

    ]);

1 个答案:

答案 0 :(得分:0)

为日期选择器添加id属性:

        echo DatePicker::widget([
        'id'=>'mydatepicker',
        'model' => $model,
        'attribute' => 'ValidFrom',
        'attribute2' => 'ValidUpto',
        'options' => ['placeholder' => 'valid from',

        ],
        'options2' => ['placeholder' => 'valid to'],
        'type' => DatePicker::TYPE_RANGE,
        'form' => $form,

        'pluginOptions' => [
            'format' => 'yyyy-mm-dd',
            'autoclose' => true,
        ],

    ]); 

将minDate设置为视图文件中的日期选择器:

    <?
    $script = <<< JS
    $( "#mydatepicker").datepicker({dateFormat: "yyyy-mm-dd", minDate: 0});
    JS;
    $this->registerJs($script, View::POS_END);
    ?>