防止显示小时输入 - DateTimeType

时间:2017-10-17 12:47:35

标签: symfony datetime fosuserbundle symfony-forms

我知道 with_seconds with_minutes 等选项,但我正在寻找停止在DateTimeType字段中渲染我的小时输入的内容。现在它看起来像这样: enter image description here

我的问题怎么可能在第二行避免这种输入? 也许有表格主题,但我想考虑另一种选择。

我的RegistrationFormType:

<?php

namespace AppBundle\Form;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\Form\Extension\Core\Type\DateTimeType;


class RegistrationType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
    $builder->add('sex', ChoiceType::class, array(
        'choices' => array(
            'Mężczyzna' => 'Mężczyzna',
            'Kobieta' => 'Kobieta'
        ),
        'expanded'=> true,
        'multiple' => false,
        'required' => true
    ));
    $builder->add('birthday_date', DateTimeType::class, array(
        'placeholder' => array(
            'year' => 'Year', 'month' => 'Month', 'day' => 'Day'
        ),
        'years' => range(1960, 2017),
        'with_minutes' => false,
        'hours' => array()
    ));
    $builder->add('about_me', TextareaType::class);
}
public function getParent()
{
    return 'FOS\UserBundle\Form\Type\RegistrationFormType';
}
public function getBlockPrefix()
{
    return 'app_user_registration';
}
}

我正在使用FOSUserBundle,所以现在这是我的表单模板:

{% trans_default_domain 'FOSUserBundle' %}

{{ form_start(form, {'method': 'post', 'action': path('fos_user_registration_register'), 'attr': {'class': 'fos_user_registration_register'}}) }}
{{ form_widget(form) }}
<div>
    <input type="submit" value="{{ 'registration.submit'|trans }}" />
</div>
{{ form_end(form) }}

提前谢谢你!

1 个答案:

答案 0 :(得分:1)

如果您不需要时间,为什么要使用DateTimeType? 尝试使用DateType或BirthdayType(doc