【问题标题】:Symfony2 form - Customize birthday typeSymfony2 表单 - 自定义生日类型
【发布时间】:2013-09-20 09:03:54
【问题描述】:

如何在 Symfony2 中自定义生日类型?没有

{% block birthday_widget %}

form_div_layout

【问题讨论】:

  • @NitishKumar 在selectbox 中。所以上面的例子应该是<select id="dateOfBirth_month" required="required" name="[dateOfBirth][month]" class="valid span2">
  • @NitishKumar 如果你看上面的代码,我在类中添加了 span2

标签: forms symfony


【解决方案1】:

生日表单类型使用 blockchoice_widget 呈现。

{% block choice_widget %}
{% spaceless %}
    {% if expanded %}
        {{ block('choice_widget_expanded') }}
    {% else %}
        {{ block('choice_widget_collapsed') }}
    {% endif %}
{% endspaceless %}
{% endblock choice_widget %}

最后,执行输出的块被命名为choice_widget_collapsed。只需在其中进行更改即可。

{% block choice_widget_collapsed %}
{% spaceless %}
    {% if required and empty_value is none and not empty_value_in_choices %}
        {% set required = false %}
    {% endif %}
    <select {{ block('widget_attributes') }}{% if multiple %} multiple="multiple"{% endif %}>
        {% if empty_value is not none %}
            <option value=""{% if required and value is empty %} selected="selected"{% endif %}>{{ empty_value|trans({}, translation_domain) }}</option>
        {% endif %}
        {% if preferred_choices|length > 0 %}
            {% set options = preferred_choices %}
            {{ block('choice_widget_options') }}
            {% if choices|length > 0 and separator is not none %}
                <option disabled="disabled">{{ separator }}</option>
            {% endif %}
        {% endif %}
        {% set options = choices %}
        {{ block('choice_widget_options') }}
    </select>
{% endspaceless %}
{% endblock choice_widget_collapsed %}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多