【问题标题】:How to only select year in DateTimeType Forms Symfony 4如何仅在 DateTimeType 表单 Symfony 4 中选择年份
【发布时间】:2020-12-20 07:46:25
【问题描述】:

所以我的 FormType 中有这段代码

    $builder
->add('anio', DateTimeType::class, [
                    'widget' => 'choice',
                    //'years' => range(date('Y')-1, date('Y')+1),
                    'format' => 'yyyy'
    
                ])

我只想显示一个年份选择器,而不是整个时间 m-d-Y h-m。

这可能吗? 太棒了!

【问题讨论】:

    标签: php forms symfony datetime symfony4


    【解决方案1】:

    遵循 Symfony 文档中的此文档:

    https://symfony.com/doc/current/reference/forms/types/datetime.html#input-format

    你需要这样做:

    ->add('anio', DateTimeType::class, [
         'input_format' => 'Y',    
    ])
    

    【讨论】:

      猜你喜欢
      • 2016-01-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-11-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-11-29
      相关资源
      最近更新 更多