【问题标题】:how to add attribute to symfony form collectionType element如何将属性添加到 symfony 表单 collectionType 元素
【发布时间】:2016-11-01 16:09:09
【问题描述】:

我在 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
 ))

提前谢谢你!

【问题讨论】:

    标签: php forms symfony collections attributes


    【解决方案1】:

    一切正常,但您使用了错误的密钥:

    'entry_type' => TextareaType::class,
    'entry_options'  => array(
      'attr' => array(
          'rows' => 10
      )),
    

    应该这样做

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-02-27
      • 1970-01-01
      • 2023-03-17
      • 1970-01-01
      相关资源
      最近更新 更多