2016-07-28 140 views
0

我想在ValidFrom中顯示大於當前日期 的日期,並且在ValidUpto字段中的日期大於ValidFrom,但無法顯示。我想要在日期選擇器中隱藏以前的日期。yii2 datepicker顯示開始日期大於當前日期

我的代碼如下。

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, 
     ], 

    ]); 

回答

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); 
    ?>