form_custom_template.tpl 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500
  1. {# Widgets #}
  2. {% block form_widget %}
  3. {% spaceless %}
  4. {% if compound %}
  5. {{ block('form_widget_compound') }}
  6. {% else %}
  7. {{ block('form_widget_simple') }}
  8. {% endif %}
  9. {% endspaceless %}
  10. {% endblock form_widget %}
  11. {% block form_widget_simple %}
  12. {% spaceless %}
  13. {% set type = type|default('text') %}
  14. {% if attr.prepend_input is defined and attr.append_input is defined and attr.prepend_input is not empty and attr.append_input is not empty %}
  15. {{ block('form_widget_prepend_append_input') }}
  16. {% elseif attr.prepend_input is defined and attr.prepend_input is not empty %}
  17. {{ block('form_widget_prepend_input') }}
  18. {% elseif attr.append_input is defined and attr.append_input is not empty %}
  19. {{ block('form_widget_append_input') }}
  20. {% else %}
  21. <input type="{{ type }}" {{ block('widget_attributes') }} {% if value is not empty %}value="{{ value }}" {% endif %}>
  22. {% endif %}
  23. {% if attr.help_block is defined %}
  24. {{ block('help_block') }}
  25. {% endif %}
  26. {% if attr.help is defined %}
  27. {{ block('help_inline') }}
  28. {% endif %}
  29. {% endspaceless %}
  30. {% endblock form_widget_simple %}
  31. {% block form_widget_prepend_append_input %}
  32. {% spaceless %}
  33. <div class="input-prepend input-append">
  34. <span class="add-on">{{ attr.prepend_input|trans({}, translation_domain) }}</span>
  35. {% set append_input = attr.append_input|trans({}, translation_domain) %}
  36. {% set attr = attr|merge({'prepend_input': '', 'append_input': ''}) %}
  37. {{ block('form_widget_simple') }}
  38. <span class="add-on">{{ append_input }}</span>
  39. </div>
  40. {% endspaceless %}
  41. {% endblock form_widget_prepend_append_input %}
  42. {% block form_widget_prepend_input %}
  43. {% spaceless %}
  44. <div class="input-prepend">
  45. <span class="add-on">{{ attr.prepend_input|trans({}, translation_domain) }}</span>
  46. {% set attr = attr|merge({'prepend_input': ''}) %}
  47. {{ block('form_widget_simple') }}
  48. </div>
  49. {% endspaceless %}
  50. {% endblock form_widget_prepend_input %}
  51. {% block form_widget_append_input %}
  52. {% spaceless %}
  53. <div class="input-append">
  54. {% set append_input = attr.append_input|trans({}, translation_domain) %}
  55. {% set attr = attr|merge({'append_input': ''}) %}
  56. {{ block('form_widget_simple') }}
  57. <span class="add-on">{{ append_input }}</span>
  58. </div>
  59. {% endspaceless %}
  60. {% endblock form_widget_append_input %}
  61. {% block form_widget_compound %}
  62. {% spaceless %}
  63. {% if form.parent is empty %}
  64. {{ form_errors(form) }}
  65. {% endif %}
  66. {{ block('form_rows') }}
  67. {{ form_rest(form) }}
  68. {% endspaceless %}
  69. {% endblock form_widget_compound %}
  70. {% block collection_widget %}
  71. {% spaceless %}
  72. {% if prototype is defined %}
  73. {% set attr = attr|merge({'data-prototype': form_row(prototype) }) %}
  74. {% endif %}
  75. {{ block('form_widget') }}
  76. {% endspaceless %}
  77. {% endblock collection_widget %}
  78. {% block textarea_widget %}
  79. {% spaceless %}
  80. <textarea {{ block('widget_attributes') }}>{{ value }}</textarea>
  81. {% endspaceless %}
  82. {% endblock textarea_widget %}
  83. {% block choice_widget %}
  84. {% spaceless %}
  85. {% if expanded %}
  86. {{ block('choice_widget_expanded') }}
  87. {% else %}
  88. {{ block('choice_widget_collapsed') }}
  89. {% endif %}
  90. {% endspaceless %}
  91. {% endblock choice_widget %}
  92. {% block choice_widget_expanded %}
  93. {% spaceless %}
  94. {% set child_vars = {'attr': attr} %}
  95. {% for child in form %}
  96. {{ form_label(child, label, child_vars) }}
  97. {% endfor %}
  98. {% endspaceless %}
  99. {% endblock choice_widget_expanded %}
  100. {% block choice_widget_collapsed %}
  101. {% spaceless %}
  102. <select {{ block('widget_attributes') }}{% if multiple %} multiple="multiple"{% endif %}>
  103. {% if empty_value is not none %}
  104. <option value="">{{ empty_value|trans({}, translation_domain) }}</option>
  105. {% endif %}
  106. {% if preferred_choices|length > 0 %}
  107. {% set options = preferred_choices %}
  108. {{ block('choice_widget_options') }}
  109. {% if choices|length > 0 and separator is not none %}
  110. <option disabled="disabled">{{ separator }}</option>
  111. {% endif %}
  112. {% endif %}
  113. {% set options = choices %}
  114. {{ block('choice_widget_options') }}
  115. </select>
  116. {% endspaceless %}
  117. {% endblock choice_widget_collapsed %}
  118. {% block choice_widget_options %}
  119. {% spaceless %}
  120. {% for group_label, choice in options %}
  121. {% if choice is iterable %}
  122. <optgroup label="{{ group_label|trans({}, translation_domain) }}">
  123. {% set options = choice %}
  124. {{ block('choice_widget_options') }}
  125. </optgroup>
  126. {% else %}
  127. <option value="{{ choice.value }}"{% if choice is selectedchoice(value) %} selected="selected"{% endif %}>{{ choice.label|trans({}, translation_domain) }}</option>
  128. {% endif %}
  129. {% endfor %}
  130. {% endspaceless %}
  131. {% endblock choice_widget_options %}
  132. {% block checkbox_widget %}
  133. {% spaceless %}
  134. <input type="checkbox" {{ block('widget_attributes') }}{% if value is defined %} value="{{ value }}"{% endif %}{% if checked %} checked="checked"{% endif %}>
  135. {% endspaceless %}
  136. {% endblock checkbox_widget %}
  137. {% block radio_widget %}
  138. {% spaceless %}
  139. <input type="radio" {{ block('widget_attributes') }}{% if value is defined %} value="{{ value }}"{% endif %}{% if checked %} checked="checked"{% endif %}>
  140. {% endspaceless %}
  141. {% endblock radio_widget %}
  142. {% block datetime_widget %}
  143. {% spaceless %}
  144. {% if widget == 'single_text' %}
  145. {{ block('form_widget_simple') }}
  146. {% else %}
  147. <div {{ block('widget_container_attributes') }}>
  148. {{ form_errors(form.date) }}
  149. {{ form_errors(form.time) }}
  150. {{ form_widget(form.date) }}
  151. {{ form_widget(form.time) }}
  152. </div>
  153. {% endif %}
  154. {% endspaceless %}
  155. {% endblock datetime_widget %}
  156. {% block date_widget %}
  157. {% spaceless %}
  158. {% if widget == 'single_text' %}
  159. {{ block('form_widget_simple') }}
  160. {% else %}
  161. <div {{ block('widget_container_attributes') }}>
  162. {{ date_pattern|replace({
  163. '{{ year }}': form_widget(form.year),
  164. '{{ month }}': form_widget(form.month),
  165. '{{ day }}': form_widget(form.day),
  166. })|raw }}
  167. </div>
  168. {% endif %}
  169. {% endspaceless %}
  170. {% endblock date_widget %}
  171. {% block time_widget %}
  172. {% spaceless %}
  173. {% if widget == 'single_text' %}
  174. {{ block('form_widget_simple') }}
  175. {% else %}
  176. <div {{ block('widget_container_attributes') }}>
  177. {{ form_widget(form.hour, { 'attr': { 'size': '1' } }) }}:{{ form_widget(form.minute, { 'attr': { 'size': '1' } }) }}{% if with_seconds %}:{{ form_widget(form.second, { 'attr': { 'size': '1' } }) }}{% endif %}
  178. </div>
  179. {% endif %}
  180. {% endspaceless %}
  181. {% endblock time_widget %}
  182. {% block number_widget %}
  183. {% spaceless %}
  184. {# type="number" doesn't work with floats #}
  185. {% set type = type|default('text') %}
  186. {{ block('form_widget_simple') }}
  187. {% endspaceless %}
  188. {% endblock number_widget %}
  189. {% block integer_widget %}
  190. {% spaceless %}
  191. {% set type = type|default('number') %}
  192. {{ block('form_widget_simple') }}
  193. {% endspaceless %}
  194. {% endblock integer_widget %}
  195. {% block money_widget %}
  196. {% spaceless %}
  197. {{ money_pattern|replace({ '{{ widget }}': block('form_widget_simple') })|raw }}
  198. {% endspaceless %}
  199. {% endblock money_widget %}
  200. {% block url_widget %}
  201. {% spaceless %}
  202. {% set type = type|default('url') %}
  203. {{ block('form_widget_simple') }}
  204. {% endspaceless %}
  205. {% endblock url_widget %}
  206. {% block search_widget %}
  207. {% spaceless %}
  208. {% set attr = attr|merge({'class': (attr.class|default('') ~ ' search-query')|trim}) %}
  209. {% set type = type|default('search') %}
  210. {{ block('form_widget_simple') }}
  211. {% endspaceless %}
  212. {% endblock search_widget %}
  213. {% block percent_widget %}
  214. {% spaceless %}
  215. {% set type = type|default('text') %}
  216. {{ block('form_widget_simple') }} %
  217. {% endspaceless %}
  218. {% endblock percent_widget %}
  219. {% block password_widget %}
  220. {% spaceless %}
  221. {% set type = type|default('password') %}
  222. {{ block('form_widget_simple') }}
  223. {% endspaceless %}
  224. {% endblock password_widget %}
  225. {% block hidden_widget %}
  226. {% spaceless %}
  227. {% set type = type|default('hidden') %}
  228. {{ block('form_widget_simple') }}
  229. {% endspaceless %}
  230. {% endblock hidden_widget %}
  231. {% block email_widget %}
  232. {% spaceless %}
  233. {% set type = type|default('email') %}
  234. {{ block('form_widget_simple') }}
  235. {% endspaceless %}
  236. {% endblock email_widget %}
  237. {# Labels #}
  238. {% block form_label %}
  239. {% spaceless %}
  240. {% if not compound %}
  241. {% set label_attr = label_attr|merge({'for': id}) %}
  242. {% endif %}
  243. {% if required %}
  244. {% set label_attr = label_attr|merge({'class': (label_attr.class|default('') ~ ' required')|trim}) %}
  245. {% endif %}
  246. {% if form_type is defined and form_type == 'horizontal' %}
  247. {% set label_attr = label_attr|merge({'class': (label_attr.class|default('') ~ ' control-label')|trim}) %}
  248. {% endif %}
  249. {% if label is empty %}
  250. {% set label = name|humanize %}
  251. {% endif %}
  252. <label{% for attrname, attrvalue in label_attr %} {{ attrname }}="{{ attrvalue }}"{% endfor %}>{{ label|trans({}, translation_domain) }}</label>
  253. {% endspaceless %}
  254. {% endblock form_label %}
  255. {% block checkbox_label %}
  256. {% spaceless %}
  257. {% if not compound %}
  258. {% set label_attr = label_attr|merge({'for': id}) %}
  259. {% endif %}
  260. {% set label_attr = label_attr|merge({'class': (label_attr.class|default('') ~ ' checkbox')|trim}) %}
  261. {% if attr.inline is defined and attr.inline %}
  262. {% set label_attr = label_attr|merge({'class': (label_attr.class|default('') ~ ' inline')|trim}) %}
  263. {% endif %}
  264. {% if required %}
  265. {% set label_attr = label_attr|merge({'class': (label_attr.class|default('') ~ ' required')|trim}) %}
  266. {% endif %}
  267. {% if label is empty %}
  268. {% set label = name|humanize %}
  269. {% endif %}
  270. {% endspaceless %}
  271. <label{% for attrname, attrvalue in label_attr %} {{ attrname }}="{{ attrvalue }}"{% endfor %}>
  272. {{ form_widget(form) }} {{ label|trans({}, translation_domain) }}
  273. </label>
  274. {% endblock checkbox_label %}
  275. {% block radio_label %}
  276. {% spaceless %}
  277. {% if not compound %}
  278. {% set label_attr = label_attr|merge({'for': id}) %}
  279. {% endif %}
  280. {% set label_attr = label_attr|merge({'class': (label_attr.class|default('') ~ ' radio')|trim}) %}
  281. {% if required %}
  282. {% set label_attr = label_attr|merge({'class': (label_attr.class|default('') ~ ' required')|trim}) %}
  283. {% endif %}
  284. {% if label is empty %}
  285. {% set label = name|humanize %}
  286. {% endif %}
  287. {% endspaceless %}
  288. <label{% for attrname, attrvalue in label_attr %} {{ attrname }}="{{ attrvalue }}"{% endfor %}>
  289. {{ form_widget(form) }} {{ label|trans({}, translation_domain) }}
  290. </label>
  291. {% endblock radio_label %}
  292. {# Rows #}
  293. {% block repeated_row %}
  294. {% spaceless %}
  295. {#
  296. No need to render the errors here, as all errors are mapped
  297. to the first child (see RepeatedTypeValidatorExtension).
  298. #}
  299. {{ block('form_rows') }}
  300. {% endspaceless %}
  301. {% endblock repeated_row %}
  302. {% block form_row %}
  303. {% spaceless %}
  304. {% if form_type is defined and form_type == 'inline' %}
  305. {{ block('inline_row') }}
  306. {% elseif form_type is defined and form_type == 'horizontal' %}
  307. {{ block('horizontal_row') }}
  308. {% else %}
  309. {{ form_label(form) }}
  310. {{ form_widget(form) }}
  311. {{ form_errors(form) }}
  312. {% endif %}
  313. {% endspaceless %}
  314. {% endblock form_row %}
  315. {% block inline_row %}
  316. {{ form_widget(form) }}&nbsp;
  317. {% endblock inline_row %}
  318. {% block horizontal_row %}
  319. {% spaceless %}
  320. <div class="control-group{% if errors|length %} error{% endif %}">
  321. {{ form_label(form) }}
  322. <div class="controls">
  323. {{ form_widget(form) }}
  324. {{ form_errors(form) }}
  325. </div>
  326. </div>
  327. {% endspaceless %}
  328. {% endblock horizontal_row %}
  329. {% block checkbox_row %}
  330. {% spaceless %}
  331. {#
  332. In order to make the click area bigger, the checkbox is
  333. placed inside the label. See checkbox_label block.
  334. #}
  335. {% if form_type is defined and form_type == 'horizontal' %}
  336. {{ block('horizontal_checkbox_row') }}
  337. {% else %}
  338. {{ form_label(form) }}
  339. {{ form_errors(form) }}
  340. {% endif %}
  341. {% endspaceless %}
  342. {% endblock checkbox_row %}
  343. {% block horizontal_checkbox_row %}
  344. {% spaceless %}
  345. <div class="control-group">
  346. <div class="controls">
  347. {{ form_label(form) }}
  348. {{ form_errors(form) }}
  349. </div>
  350. </div>
  351. {% endspaceless %}
  352. {% endblock horizontal_checkbox_row %}
  353. {% block search_row %}
  354. {% spaceless %}
  355. {{ form_widget(form) }}
  356. {{ form_errors(form) }}
  357. {% endspaceless %}
  358. {% endblock search_row %}
  359. {% block hidden_row %}
  360. {{ form_widget(form) }}
  361. {% endblock hidden_row %}
  362. {# Misc #}
  363. {% block form_enctype %}
  364. {% spaceless %}
  365. {% if multipart %}enctype="multipart/form-data"{% endif %}
  366. {% endspaceless %}
  367. {% endblock form_enctype %}
  368. {% block form_errors %}
  369. {% spaceless %}
  370. {% if errors|length == 1 %}
  371. <span class="help-inline">{{
  372. errors[0].messagePluralization is null
  373. ? errors[0].messageTemplate|trans(errors[0].messageParameters, 'validators')
  374. : errors[0].messageTemplate|transchoice(errors[0].messagePluralization, errors[0].messageParameters, 'validators')
  375. }}</span>
  376. {% elseif errors|length > 0 %}
  377. <ul class="help-block">
  378. {% for error in errors %}
  379. <li>{{
  380. error.messagePluralization is null
  381. ? error.messageTemplate|trans(error.messageParameters, 'validators')
  382. : error.messageTemplate|transchoice(error.messagePluralization, error.messageParameters, 'validators')
  383. }}</li>
  384. {% endfor %}
  385. </ul>
  386. {% endif %}
  387. {% endspaceless %}
  388. {% endblock form_errors %}
  389. {% block form_rest %}
  390. {% spaceless %}
  391. {% for child in form %}
  392. {% if not child.rendered %}
  393. {{ form_row(child) }}
  394. {% endif %}
  395. {% endfor %}
  396. {% endspaceless %}
  397. {% endblock form_rest %}
  398. {% block help_block %}
  399. {% spaceless %}
  400. {% if attr.help_block is defined %}
  401. <span class="help-block">{{ attr.help_block|trans({}, translation_domain) }}</span>
  402. {% endif %}
  403. {% endspaceless %}
  404. {% endblock help_block %}
  405. {% block help_inline %}
  406. {% spaceless %}
  407. {% if attr.help is defined %}
  408. <span class="help-inline">{{ attr.help|trans({}, translation_domain) }}</span>
  409. {% endif %}
  410. {% endspaceless %}
  411. {% endblock help_inline %}
  412. {# Support #}
  413. {% block form_rows %}
  414. {% spaceless %}
  415. {% set child_vars = {} %}
  416. {% if form_type is defined %}
  417. {% set child_vars = child_vars|merge({'form_type': form_type}) %}
  418. {% else %}
  419. {% set child_vars = child_vars|merge({'form_type': 'horizontal'}) %}
  420. {% endif %}
  421. {% for child in form %}
  422. {{ form_row(child, child_vars) }}
  423. {% endfor %}
  424. {% endspaceless %}
  425. {% endblock form_rows %}
  426. {% block widget_attributes %}
  427. {% spaceless %}
  428. id="{{ id }}" name="{{ full_name }}"{% if read_only %} readonly="readonly"{% endif %}{% if disabled %} disabled="disabled"{% endif %}{% if required %} required="required"{% endif %}{% if max_length %} maxlength="{{ max_length }}"{% endif %}{% if pattern %} pattern="{{ pattern }}"{% endif %}
  429. {% for attrname, attrvalue in attr %}{% if attrname in ['placeholder', 'title'] %}{{ attrname }}="{{ attrvalue|trans({}, translation_domain) }}" {% else %}{{ attrname }}="{{ attrvalue }}" {% endif %}{% endfor %}
  430. {% endspaceless %}
  431. {% endblock widget_attributes %}
  432. {% block widget_container_attributes %}
  433. {% spaceless %}
  434. {% if id is not empty %}id="{{ id }}" {% endif %}
  435. {% for attrname, attrvalue in attr %}{{ attrname }}="{{ attrvalue }}" {% endfor %}
  436. {% endspaceless %}
  437. {% endblock widget_container_attributes %}
  438. {# Deprecated in Symfony 2.1, to be removed in 2.3 #}
  439. {% block generic_label %}{{ block('form_label') }}{% endblock %}
  440. {% block widget_choice_options %}{{ block('choice_widget_options') }}{% endblock %}
  441. {% block field_widget %}{{ block('form_widget_simple') }}{% endblock %}
  442. {% block field_label %}{{ block('form_label') }}{% endblock %}
  443. {% block field_row %}{{ block('form_row') }}{% endblock %}
  444. {% block field_enctype %}{{ block('form_enctype') }}{% endblock %}
  445. {% block field_errors %}{{ block('form_errors') }}{% endblock %}
  446. {% block field_rest %}{{ block('form_rest') }}{% endblock %}
  447. {% block field_rows %}{{ block('form_rows') }}{% endblock %}