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'));
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 宇视监控服务器无法登录
  • ¥15 PADS Logic 原理图
  • ¥15 PADS Logic 图标
  • ¥15 电脑和power bi环境都是英文如何将日期层次结构转换成英文
  • ¥15 DruidDataSource一直closing
  • ¥20 气象站点数据求取中~
  • ¥15 如何获取APP内弹出的网址链接
  • ¥15 wifi 图标不见了 不知道怎么办 上不了网 变成小地球了
  • ¥50 STM32单片机传感器读取错误
  • ¥50 power BI 从Mysql服务器导入数据,但连接进去后显示表无数据