silex_form_div_layout.html.twig 3.2 KB

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