简体   繁体   English

如何在Symfony2中为两个输入所呈现的表单字段设置属性

[英]How to set attributes for form field rendered by two inputs in Symfony2

I have date field in symfony2 which is rendered by two inputs: 我在symfony2中有date字段,它由两个输入呈现:

   $builder

            ->add('timeStart','datetime',array(
                'date_widget' => 'single_text',
                'time_widget' => 'single_text',
                'date_format' => 'yyyy-MM-dd',
                'data' => new \DateTime('now')
            ))

how to set attributes for each input? 如何为每个输入设置属性? When I add attr=>array('some_attr'=>'some_value') it is added to the div in which those inputs are, not to each input. 当我添加attr=>array('some_attr'=>'some_value')它会添加到这些输入所在的div中,而不是每个输入中。

You need to set each's input attribute when rendering inside the twig template. 在树枝图样内部进行渲染时,需要设置每个对象的输入属性。 Something like this would do: 这样的事情会做:

{{ form_widget(form.timeStart, { attributes1 } ) }}

And

{{ form_widget(form.timeStart, { attributes2 } ) }}

Take a look at the docs . 看一下docs

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM