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 FPGA-SRIO初始化失败
  • ¥15 MapReduce实现倒排索引失败
  • ¥15 ZABBIX6.0L连接数据库报错,如何解决?(操作系统-centos)
  • ¥15 找一位技术过硬的游戏pj程序员
  • ¥15 matlab生成电测深三层曲线模型代码
  • ¥50 随机森林与房贷信用风险模型
  • ¥50 buildozer打包kivy app失败
  • ¥30 在vs2022里运行python代码
  • ¥15 不同尺寸货物如何寻找合适的包装箱型谱
  • ¥15 求解 yolo算法问题