Symfony splitted embedded form
I work with a symfony embedded form to manage my translated fields for a given entity. My principal entity has a boolean field and I have multiple text fields for each translation.
I do not use the translatable doctrine extension and I do not want to use it.
In my FormType, I use a CollectionType to embed the translated fields in my form, and in the template, I use the form theme to customize the HTML.
This is my problem : I would like to group fields in my form to optimize UX but once I call the form_widget on my field, I cannot use it a second time. I would like to show 2 fields for a given language and then another field for another language further in the form. How can I solve my problem ?
This is a twig example that illustrate my problem.
{% form_theme form _self %}
{% block _service_translations_entry_widget %}
<div>
{% if name == 0 %}
<div class="s12 m6 l6">
{{ form_label(form.title) }}
{{ form_errors(form.title) }}
{{ form_widget(form.title) }}
</div>
<div class="s12 m6 l6">
{{ form_label(form.subtitle) }}
{{ form_errors(form.subtitle) }}
{{ form_widget(form.subtitle) }}
</div>
{% endif %}
{% if name == 1 %}
<div class="s12 m12 l12">
{{ form_label(form.desc) }}
{{ form_errors(form.desc) }}
{{ form_widget(form.desc) }}
</div>
{% endif %}
</div>
{% endblock %}
{% block body %}
{{ form_start() }}
{{ form_errors(form) }}
<div>
<div class="s12 m12 l12">
{{ form_label(form.doubleBlock) }}
{{ form_errors(form.doubleBlock) }}
{{ form_widget(form.doubleBlock) }}
</div>
</div>
<div id="block-1">
{{ form_widget(form.translations) }}
</div>
<div>
<div class="s12 m6 l6">
{{ form_label(form.activedStyle) }}
{{ form_errors(form.activedStyle) }}
{{ form_widget(form.activedStyle) }}
</div>
<div class="s12 m6 l6">
{{ form_label(form.checkoutOption) }}
{{ form_errors(form.checkoutOption) }}
{{ form_widget(form.checkoutOption) }}
</div>
</div>
<div id="block-2">
{{ form_widget(form.translations) }}
</div>
{{ form_widget(form.save) }}
{{ form_rest(form) }}
{{ form_end(form) }}
{% endblock body %}
链接地址: http://www.djcxy.com/p/81408.html上一篇: 用自己替换片段不会显示任何内容
下一篇: Symfony拆分了嵌入式表单