【问题标题】:How to render dynamic or responsive form fields using form type symfony?如何使用表单类型 symfony 呈现动态或响应式表单字段?
【发布时间】:2016-03-28 09:41:47
【问题描述】:

我在 twig 中渲染了来自数据库 mapset 的五个数据条目:

 {{ form_start(form) }}
    {% for item in mapset %}
       <tr> 
         <td>{{ item.name }}</td>
         <td>{{ form_widget(form.sets) }}</td>
         <td>{{ form_widget(form.options) }}</td>
         <td>{{ form_widget(form.buttonSet) }}</td>
         <td>{{ form_widget(form.buttonItem) }}</td>
       </tr>
    {% endfor %}
  {{ form_end(form) }}

此表单应呈现总共 20 个输入,如下所示:

  name1  [] [] [] []
  name2  [] [] [] []
  name3  [] [] [] []
  name4  [] [] [] []
  name5  [] [] [] []

但我的代码显示:

 name1  [] [] [] []
 name2
 name3
 name4
 name5

我已经阅读了很多关于动态表单和表单集合的内容,但我不明白。

【问题讨论】:

    标签: php forms symfony


    【解决方案1】:
    {# src/AppBundle/Resources/views/Task/new.html.twig #}
    
    {# ... #}
    
    {{ form_start(form) }}
        {# render the task's only field: description #}
        {{ form_row(form.description) }}
    
        <h3>Tags</h3>
        <ul class="tags">
            {# iterate over each existing tag and render its only field: name #}
            {% for tag in form.tags %}
                <li>{{ form_row(tag.name) }}</li>
            {% endfor %}
        </ul>
    {{ form_end(form) }}
    
    {# ... #}
    

    http://symfony.com/doc/2.7/cookbook/form/form_collections.html

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-09-23
      • 1970-01-01
      • 1970-01-01
      • 2019-07-21
      • 2020-09-19
      • 1970-01-01
      • 2018-07-28
      相关资源
      最近更新 更多