Forms Symfony2表单自定义
我想要这样的东西:Forms Symfony2表单自定义,forms,symfony,twig,Forms,Symfony,Twig,我想要这样的东西: <textarea rows="30" cols="70" class="TextBox" style="height:100px;"> <label for="history">{{'form_anamnese_history'}}</label> {{ form_widget(form.history) }} 但我知道“行”和“列”不是选项 在树枝上,我想要这样的东西: <textarea rows="30" cols="7
<textarea rows="30" cols="70" class="TextBox" style="height:100px;">
<label for="history">{{'form_anamnese_history'}}</label>
{{ form_widget(form.history) }}
但我知道“行”和“列”不是选项
在树枝上,我想要这样的东西:
<textarea rows="30" cols="70" class="TextBox" style="height:100px;">
<label for="history">{{'form_anamnese_history'}}</label>
{{ form_widget(form.history) }}
{{'form\u anamnese\u history'}
{{form_小部件(form.history)}
成为一个像文本框一样的论坛帖子 使用
attr
数组,如下所述:
您可以在Twig中而不是在表单中设置textarea的显示属性:
{{ form_widget(edit_form.comment, { 'attr': {
'style' : 'width:525px',
'rows' : '4',
'cols' : '30' }} ) }}
如上所述,如果可能,最好在CSS中设置此选项。解决
Symfony 3
中的问题
第一:
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
第二:
以下是代码的格式:
->add('biografia', TextareaType::class, array(
'label' => 'Como me identifico, Identifiquese utilizando un máximo de 500 caracteres',
'attr' => array('class' => 'myclass')
))
在css中调整元素的大小更好。根据我的经验,最好使用行和列,因为它会自动匹配行高度。在twig视图中定义
行
和列
在symfony 2.8上不起作用。正如@juan所指出的,它只在表单构建期间起作用。我认为这是最好的答案,因为表单小部件的物理尺寸应该是特定的细枝模板的问题,而不是表单类型类本身的问题。