1

我有这个自定义表单域

{# src/Acme/DemoBundle/Resources/views/Form/fields.html.twig #}
{% block gender_widget %}
    {% spaceless %}
        {% if expanded %}
            <ul {{ block('widget_container_attributes') }}>
            {% for child in form %}
                <li>
                    {{ form_widget(child) }}
                    {{ form_label(child) }}
                </li>
            {% endfor %}
            </ul>
        {% else %}
            {# just let the choice widget render the select tag #}
            {{ block('choice_widget') }}
        {% endif %}
    {% endspaceless %}
{% endblock %}

这将呈现复选框。但我无法找到如何获得复选框的值

child.form.value不工作。

假设我有在表单中被命名为任务的实体。

我怎样才能得到taskid的值。

就像是

child.form.vars.task.id

4

1 回答 1

1

好像在{{ choice.value }}

看看这个,看看继承是如何工作的。

<option value="{{ choice.value }}"{% if choice is selectedchoice(value) %} selected="selected"{% endif %}>{{ choice.label|trans({}, translation_domain) }}</option>
于 2012-08-25T03:03:06.003 回答