silex_form_div_layout.html.twig 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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 generic_label %}
  38. {% spaceless %}
  39. {% if required %}
  40. {% set attr = attr|merge({'class': attr.class|default('') ~ ' required'}) %}
  41. {% endif %}
  42. {% if in_list_checkbox is defined and in_list_checkbox and widget is defined %}
  43. <label{% for attrname,attrvalue in attr %} {{attrname}}="{{attrvalue}}"{% endfor %}>
  44. {{ widget|raw }}
  45. <span>
  46. {{ label|trans }}
  47. </span>
  48. </label>
  49. {% else %}
  50. <label{% for attrname,attrvalue in attr %} {{attrname}}="{{attrvalue}}"{% endfor %}>{{ label|trans }}</label>
  51. {% endif %}
  52. {% endspaceless %}
  53. {% endblock %}
  54. {# Rows #}
  55. {% block field_row %}
  56. {% spaceless %}
  57. <div class="clearfix {{ (0 < form_errors(form)|length)? 'error':'' }} ">
  58. {{ form_label(form, label|default(null)) }}
  59. <div class="input">
  60. {{ form_widget(form) }}
  61. {{ form_errors(form) }}
  62. </div>
  63. </div>
  64. {% endspaceless %}
  65. {% endblock field_row %}
  66. {# Misc #}
  67. {% block field_errors %}
  68. {% spaceless %}
  69. {% if errors|length > 0 %}
  70. {% if not form.hasParent or 'repeated' in form.get('types') %}
  71. <div class="clearfix error">
  72. {% endif %}
  73. <span class="help-inline">
  74. {% for error in errors %}
  75. {% if loop.first %}
  76. {{ error.messageTemplate|trans(error.messageParameters, 'validators') }}
  77. {% endif %}
  78. {% endfor %}
  79. </span>
  80. {% if not form.hasParent or 'repeated' in form.get('types') %}
  81. </div>
  82. {% endif %}
  83. {% endif %}
  84. {% endspaceless %}
  85. {% endblock field_errors %}