silex_form_div_layout.html.twig 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. {# Widgets #}
  2. {% block choice_widget %}
  3. {% spaceless %}
  4. {% if expanded %}
  5. <ul {{ block('widget_container_attributes') }} class="inputs-list">
  6. {% for child in form %}
  7. <li>
  8. {{ form_label(child, null, { 'in_list_checkbox' : true, 'widget' : form_widget(child) } ) }}
  9. </li>
  10. {% endfor %}
  11. </ul>
  12. {% else %}
  13. <select {{ block('widget_attributes') }}{% if multiple %} multiple="multiple"{% endif %}>
  14. {% if empty_value is not none %}
  15. <option value="">{{ empty_value|trans }}</option>
  16. {% endif %}
  17. {% if preferred_choices|length > 0 %}
  18. {% set options = preferred_choices %}
  19. {{ block('choice_widget_options') }}
  20. {% if choices|length > 0 and separator is not none %}
  21. <option disabled="disabled">{{ separator }}</option>
  22. {% endif %}
  23. {% endif %}
  24. {% set options = choices %}
  25. {{ block('choice_widget_options') }}
  26. </select>
  27. {% endif %}
  28. {% endspaceless %}
  29. {% endblock choice_widget %}
  30. {% block form_widget_simple %}
  31. {% spaceless %}
  32. {% set type = type|default('text') %}
  33. <input type="{{ type }}" {{ block('widget_attributes') }} value="{{ value }}" />
  34. {% endspaceless %}
  35. {% endblock form_widget_simple %}
  36. {# Labels #}
  37. {% block form_label %}
  38. {% spaceless %}
  39. {% if not compound %}
  40. {% set attr = attr|merge({'for': id}) %}
  41. {% endif %}
  42. {% if required %}
  43. {% set attr = attr|merge({'class': attr.class|default('') ~ ' required'}) %}
  44. {% endif %}
  45. {% if in_list_checkbox is defined and in_list_checkbox and widget is defined %}
  46. <label{% for attrname,attrvalue in attr %} {{attrname}}="{{attrvalue}}"{% endfor %}>
  47. {{ widget|raw }}
  48. <span>
  49. {{ label|trans }}
  50. </span>
  51. </label>
  52. {% else %}
  53. <label{% for attrname,attrvalue in attr %} {{attrname}}="{{attrvalue}}"{% endfor %}>{{ label|trans }}</label>
  54. {% endif %}
  55. {% endspaceless %}
  56. {% endblock %}
  57. {# Rows #}
  58. {% block form_row %}
  59. {% spaceless %}
  60. <div class="control-group {{ (0 < form_errors(form)|length)? 'error':'' }} ">
  61. {{ form_label(form, label|default(null)) }}
  62. <div class="controls">
  63. {{ form_widget(form) }}
  64. {{ form_errors(form) }}
  65. </div>
  66. </div>
  67. {% endspaceless %}
  68. {% endblock form_row %}
  69. {# Misc #}
  70. {% block form_errors %}
  71. {% spaceless %}
  72. {% if errors|length > 0 %}
  73. {% if not form.parent or 'repeated' in form.vars['block_prefixes'] %}
  74. <div class="control-group error">
  75. {% endif %}
  76. <span class="help-inline">
  77. {% for error in errors %}
  78. {% if loop.first %}
  79. {{ error.messageTemplate|trans(error.messageParameters, 'validators') }}
  80. {% endif %}
  81. {% endfor %}
  82. </span>
  83. {% if not form.parent or 'repeated' in form.vars['block_prefixes'] %}
  84. </div>
  85. {% endif %}
  86. {% endif %}
  87. {% endspaceless %}
  88. {% endblock form_errors %}