我在php中的表单:
class MyType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('configFiles', CollectionType::class, array(
'entry_type' => TextareaType::class,
'allow_add' => true,
'allow_delete' => true,
'by_reference' => false,
'prototype' => true
))
}
...
}
我的形式在树枝上:
...
<div class="form-group">
{{ form_label(create_lab_form.configFiles) }}
<div class="configFiles" data-prototype="{{ form_widget(create_lab_form.configFiles.vars.prototype)|e('html_attr') }}">
</div>
{{ form_errors(create_lab_form.configFiles) }}
</div>
{% do create_lab_form.configFiles.setRendered %}
</div>
...
如何在上面的示例中为Textarea集合元素添加属性(例如“行”)?
我尝试了类似的东西,但它不起作用:
->add('configFiles', CollectionType::class, array(
'entry_type' => TextareaType::class, array(
'attr' => array('rows' => 10
)),
'allow_add' => true,
'allow_delete' => true,
'by_reference' => false,
'prototype' => true
))
提前谢谢!
答案 0 :(得分:0)
一切都是正确的,但你使用了错误的密钥:
'entry_type' => TextareaType::class,
'entry_options' => array(
'attr' => array(
'rows' => 10
)),
应该做yob