silex_form_div_layout.html.twig 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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('widget_choice_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('widget_choice_options') }}
  26. </select>
  27. {% endif %}
  28. {% endspaceless %}
  29. {% endblock choice_widget %}
  30. {% block field_widget %}
  31. {% spaceless %}
  32. {% set type = type|default('text') %}
  33. <input type="{{ type }}" {{ block('widget_attributes') }} value="{{ value }}" />
  34. {% endspaceless %}
  35. {% endblock field_widget %}
  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 field_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 field_row %}
  69. {# Misc #}
  70. {% block field_errors %}
  71. {% spaceless %}
  72. {% if errors|length > 0 %}
  73. {% if not form.hasParent or 'repeated' in form.get('types') %}
  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.hasParent or 'repeated' in form.get('types') %}
  84. </div>
  85. {% endif %}
  86. {% endif %}
  87. {% endspaceless %}
  88. {% endblock field_errors %}