duanshan2988 2016-10-26 07:30
浏览 48
已采纳

yii 2日期选择器仅在今天之前允许

echo $form->field($model, 'dob')->widget(DatePicker::classname(), [
  'options' => [
    'placeholder' => Yii::t('app', 'Please pick your birth-date'), 
  ],
  'type' => DatePicker::TYPE_INPUT,
  'pluginOptions' => [
    'autoclose'=>true,
    'format' => 'dd/mm/yyyy',
    'startView' => 1,
  ],
])->label(Yii::t('app', 'Date of Birth'));

The code above is used to create a DatePicker in yii 2. Is it possible for me to only allow users to select date before today?

  • 写回答

1条回答 默认 最新

  • duanjiao2978 2016-10-26 07:53
    关注

    Yes, you can the future dates disable by endDate property of pluginOptions.

    echo $form->field($model, 'dob')->widget(DatePicker::classname(), [
      'options' => [
        'placeholder' => Yii::t('app', 'Please pick your birth-date'), 
      ],
      'type' => DatePicker::TYPE_INPUT,
      'pluginOptions' => [
        'autoclose'=>true,
        'format' => 'dd/mm/yyyy',
        'startView' => 1,
        'endDate'=>date('d/m/Y')
      ],
    ])->label(Yii::t('app', 'Date of Birth'));
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?