doutan8506 2017-11-23 11:22
浏览 124
已采纳

如何使用single_text小部件在Symfony DateType中设置日期范围

I want to create a date input with the widget => single_text type, but I only want the user to be able to select/type years between 2000 and 2099. With widget => choice this works fine, but with single_text I can write the number I want despite clearly having the range attribute set. Is there a quick way to accomplish this, or do I have to create some other validation? If so, how?

this is how it looks like with single_text

My code:

... ['respiteDate', DateType::class, [
               'required' => false,
               'widget' => 'single_text',
               'years'  =>  range(2000,2099)
               ],
           ], ...

Thanks in advance.

  • 写回答

1条回答 默认 最新

  • dongyirong3564 2017-11-23 12:22
    关注

    What you have there is a screenshot of Chrome-specific datepicker (if not mistaken). Different browsers do it in a different way and when it comes to <input type="date"/> (MDN link) their is no way to specific which years in particular are to be permitted (contrary to choice variant).

    According to standard, there is a way to specify min and max date, which you may find suitable enough - you just need to specify min="2000-01-01 and max="2099-12-31".

    Interestingly enough, DateType does not seem to support min and max attributes, so be sure to include server-side validation...

    Hope this helps...

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡等级和折扣规则
  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分