如何在Yii datepicker中禁用以前的日期

vddsk6oq  于 2022-11-09  发布在  其他
关注(0)|答案(4)|浏览(185)

我在Yii中使用日期选择器,我想禁用日历上以前的日期以避免选择它们。
下面是我的代码:

  1. $this->widget('zii.widgets.jui.CJuiDatePicker', array(
  2. 'model'=>$model,
  3. 'attribute'=>'arrival_date_as_per_recorded_travel',
  4. 'name'=>'arrival_date_as_per_recorded_travel',
  5. 'value'=>$eta_date_formatted,
  6. // additional javascript options for the date picker plugin
  7. 'options'=>array(
  8. 'startDate'=>date("yy-mm-dd"),
  9. 'showAnim'=>'fold',
  10. 'dateFormat'=>'yy-mm-dd',
  11. 'changeMonth'=>'true',
  12. 'changeYear'=>'true',
  13. 'yearRange'=>'2013:2100',),
  14. 'htmlOptions'=>array(
  15. 'id'=>'arrival_date_as_per_recorded_travel',
  16. 'style'=>'height:20px;width:150px',
  17. 'value'=>$eta_date_formatted,
  18. 'onblur'=>'if(this.value=="")this.value=""'
  19. ),
  20. ));
yquaqz18

yquaqz181#

至于Yii2(添加这个作为答案,因为这个问题没有在yii 1.x下标记)

  1. <?php
  2. use yii\jui\DatePicker;
  3. ?>
  4. <?=
  5. DatePicker::widget([
  6. 'name' => 'to_date',
  7. 'dateFormat' => 'dd/MM/yyyy',
  8. 'clientOptions' => [
  9. 'minDate' => 0
  10. ]
  11. ])
  12. ?>
plupiseo

plupiseo2#

使用以下代码更改选项

  1. 'options'=>array(
  2. 'startDate'=>date("yy-mm-dd"),
  3. 'minDate'=>'0', // this will disable previous dates from datepicker
  4. 'showAnim'=>'fold',
  5. 'dateFormat'=>'yy-mm-dd',
  6. 'changeMonth'=>'true',
  7. 'changeYear'=>'true',
  8. 'yearRange'=>'2013:2100',),

**'minDate'=〉' 0 '**将禁用以前的日期...

您可以查看Jquery日期选择器API(minDate)
希望能对你有所帮助...

3bygqnnd

3bygqnnd3#

将以下内容添加到您的选项数组中应该会有所帮助。

  1. minDate: new Date(),
0ve6wy6x

0ve6wy6x4#

我已经尝试了以前的答案,但没有工作。这里是我如何解决这个问题
1.在文档https://www.malot.fr/bootstrap-datetimepicker/中未找到minDate
1.有一个类似minDate的函数,不,它叫做startDate,但它只接受日期。

  1. startDate日期。默认值:开始时间可选择的最早日期;所有较早的日期将被禁用。如在官方文档中。
    给你。
  1. <?php
  2. $now = new DateTime();
  3. echo $form->field($data['model'], 'expire_date' ,
  4. ['template' =>
  5. '{label}<p class="sub-label">' . \Yii::t("main","After this date people won't be able to bid on this job no more.").'</p> {input}{error}{hint}'])
  6. ->widget(DateTimePicker::classname(),
  7. [
  8. 'options' => [
  9. 'placeholder' => \Yii::t("main","Enter a date..."),
  10. 'autoComplete' => 'off',
  11. ],
  12. //'convertFormat' => true,
  13. 'language' => "Yii::$app->language;",
  14. 'pluginOptions' => [
  15. 'autoclose'=>true,
  16. 'format' => 'yyyy-mm-dd hh:ii:ss',
  17. 'startDate' => date_format($now, 'Y-m-d'), //startDate Date. Default: Beginning of time The earliest date that may be selected; all earlier dates will be disabled.
  18. ]
  19. ]);?>
展开查看全部

相关问题