]> Raphaƫl G. Git Repositories - airbundle/blob - Resources/views/form/form_div_layout.html.twig
Add header around h3
[airbundle] / Resources / views / form / form_div_layout.html.twig
1 {# Widgets #}
2
3 {%- block form_widget -%}
4 {% if compound %}
5 {{- block('form_widget_compound') -}}
6 {% else %}
7 {{- block('form_widget_simple') -}}
8 {% endif %}
9 {%- endblock form_widget -%}
10
11 {%- block form_widget_simple -%}
12 {%- set type = type|default('text') -%}
13 <input type="{{ type }}" {{ block('widget_attributes') }} {% if value is not empty %}value="{{ value }}" {% endif %}/>
14 {%- endblock form_widget_simple -%}
15
16 {%- block form_widget_compound -%}
17 <div {{ block('widget_container_attributes') }}>
18 {%- if form is rootform -%}
19 {{ form_errors(form) }}
20 {%- endif -%}
21 {{- block('form_rows') -}}
22 {{- form_rest(form) -}}
23 </div>
24 {%- endblock form_widget_compound -%}
25
26 {%- block collection_widget -%}
27 {% if prototype is defined %}
28 {%- set attr = attr|merge({'data-prototype': form_row(prototype) }) -%}
29 {% endif %}
30 {{- block('form_widget') -}}
31 {%- endblock collection_widget -%}
32
33 {%- block textarea_widget -%}
34 <textarea {{ block('widget_attributes') }}>{{ value }}</textarea>
35 {%- endblock textarea_widget -%}
36
37 {%- block choice_widget -%}
38 {% if expanded %}
39 {{- block('choice_widget_expanded') -}}
40 {% else %}
41 {{- block('choice_widget_collapsed') -}}
42 {% endif %}
43 {%- endblock choice_widget -%}
44
45 {%- block choice_widget_expanded -%}
46 <div {{ block('widget_container_attributes') }}>
47 {%- for child in form %}
48 {{- form_widget(child) -}}
49 {{- form_label(child, null, {translation_domain: choice_translation_domain}) -}}
50 {% endfor -%}
51 </div>
52 {%- endblock choice_widget_expanded -%}
53
54 {%- block choice_widget_collapsed -%}
55 {%- if required and placeholder is none and not placeholder_in_choices and not multiple and (attr.size is not defined or attr.size <= 1) -%}
56 {% set required = false %}
57 {%- endif -%}
58 <select {{ block('widget_attributes') }}{% if multiple %} multiple="multiple"{% endif %}>
59 {%- if placeholder is not none -%}
60 <option value=""{% if required and value is empty %} selected="selected"{% endif %}>{{ placeholder != '' ? (translation_domain is same as(false) ? placeholder : placeholder|trans({}, translation_domain)) }}</option>
61 {%- endif -%}
62 {%- if preferred_choices|length > 0 -%}
63 {% set options = preferred_choices %}
64 {{- block('choice_widget_options') -}}
65 {%- if choices|length > 0 and separator is not none -%}
66 <option disabled="disabled">{{ separator }}</option>
67 {%- endif -%}
68 {%- endif -%}
69 {%- set options = choices -%}
70 {{- block('choice_widget_options') -}}
71 </select>
72 {%- endblock choice_widget_collapsed -%}
73
74 {%- block choice_widget_options -%}
75 {% for group_label, choice in options %}
76 {%- if choice is iterable -%}
77 <optgroup label="{{ choice_translation_domain is same as(false) ? group_label : group_label|trans({}, choice_translation_domain) }}">
78 {% set options = choice %}
79 {{- block('choice_widget_options') -}}
80 </optgroup>
81 {%- else -%}
82 <option value="{{ choice.value }}"{% if choice.attr %}{% with { attr: choice.attr } %}{{ block('attributes') }}{% endwith %}{% endif %}{% if choice is selectedchoice(value) %} selected="selected"{% endif %}>{{ choice_translation_domain is same as(false) ? choice.label : choice.label|trans({}, choice_translation_domain) }}</option>
83 {%- endif -%}
84 {% endfor %}
85 {%- endblock choice_widget_options -%}
86
87 {%- block checkbox_widget -%}
88 <input type="checkbox" {{ block('widget_attributes') }}{% if value is defined %} value="{{ value }}"{% endif %}{% if checked %} checked="checked"{% endif %} />
89 {%- endblock checkbox_widget -%}
90
91 {%- block radio_widget -%}
92 <input type="radio" {{ block('widget_attributes') }}{% if value is defined %} value="{{ value }}"{% endif %}{% if checked %} checked="checked"{% endif %} />
93 {%- endblock radio_widget -%}
94
95 {%- block datetime_widget -%}
96 {% if widget == 'single_text' %}
97 {{- block('form_widget_simple') -}}
98 {%- else -%}
99 <div {{ block('widget_container_attributes') }}>
100 {{- form_errors(form.date) -}}
101 {{- form_errors(form.time) -}}
102 {{- form_widget(form.date) -}}
103 {{- form_widget(form.time) -}}
104 </div>
105 {%- endif -%}
106 {%- endblock datetime_widget -%}
107
108 {%- block date_widget -%}
109 {%- if widget == 'single_text' -%}
110 {{ block('form_widget_simple') }}
111 {%- else -%}
112 <div {{ block('widget_container_attributes') }}>
113 {{- date_pattern|replace({
114 '{{ year }}': form_widget(form.year),
115 '{{ month }}': form_widget(form.month),
116 '{{ day }}': form_widget(form.day),
117 })|raw -}}
118 </div>
119 {%- endif -%}
120 {%- endblock date_widget -%}
121
122 {%- block time_widget -%}
123 {%- if widget == 'single_text' -%}
124 {{ block('form_widget_simple') }}
125 {%- else -%}
126 {%- set vars = widget == 'text' ? { 'attr': { 'size': 1 }} : {} -%}
127 <div {{ block('widget_container_attributes') }}>
128 {{ form_widget(form.hour, vars) }}{% if with_minutes %}:{{ form_widget(form.minute, vars) }}{% endif %}{% if with_seconds %}:{{ form_widget(form.second, vars) }}{% endif %}
129 </div>
130 {%- endif -%}
131 {%- endblock time_widget -%}
132
133 {%- block dateinterval_widget -%}
134 {%- if widget == 'single_text' -%}
135 {{- block('form_widget_simple') -}}
136 {%- else -%}
137 <div {{ block('widget_container_attributes') }}>
138 {{- form_errors(form) -}}
139 <table class="{{ table_class|default('') }}" role="presentation">
140 <thead>
141 <tr>
142 {%- if with_years %}<th>{{ form_label(form.years) }}</th>{% endif -%}
143 {%- if with_months %}<th>{{ form_label(form.months) }}</th>{% endif -%}
144 {%- if with_weeks %}<th>{{ form_label(form.weeks) }}</th>{% endif -%}
145 {%- if with_days %}<th>{{ form_label(form.days) }}</th>{% endif -%}
146 {%- if with_hours %}<th>{{ form_label(form.hours) }}</th>{% endif -%}
147 {%- if with_minutes %}<th>{{ form_label(form.minutes) }}</th>{% endif -%}
148 {%- if with_seconds %}<th>{{ form_label(form.seconds) }}</th>{% endif -%}
149 </tr>
150 </thead>
151 <tbody>
152 <tr>
153 {%- if with_years %}<td>{{ form_widget(form.years) }}</td>{% endif -%}
154 {%- if with_months %}<td>{{ form_widget(form.months) }}</td>{% endif -%}
155 {%- if with_weeks %}<td>{{ form_widget(form.weeks) }}</td>{% endif -%}
156 {%- if with_days %}<td>{{ form_widget(form.days) }}</td>{% endif -%}
157 {%- if with_hours %}<td>{{ form_widget(form.hours) }}</td>{% endif -%}
158 {%- if with_minutes %}<td>{{ form_widget(form.minutes) }}</td>{% endif -%}
159 {%- if with_seconds %}<td>{{ form_widget(form.seconds) }}</td>{% endif -%}
160 </tr>
161 </tbody>
162 </table>
163 {%- if with_invert %}{{ form_widget(form.invert) }}{% endif -%}
164 </div>
165 {%- endif -%}
166 {%- endblock dateinterval_widget -%}
167
168 {%- block number_widget -%}
169 {# type="number" doesn't work with floats #}
170 {%- set type = type|default('text') -%}
171 {{ block('form_widget_simple') }}
172 {%- endblock number_widget -%}
173
174 {%- block integer_widget -%}
175 {%- set type = type|default('number') -%}
176 {{ block('form_widget_simple') }}
177 {%- endblock integer_widget -%}
178
179 {%- block money_widget -%}
180 {{ money_pattern|replace({ '{{ widget }}': block('form_widget_simple') })|raw }}
181 {%- endblock money_widget -%}
182
183 {%- block url_widget -%}
184 {%- set type = type|default('url') -%}
185 {{ block('form_widget_simple') }}
186 {%- endblock url_widget -%}
187
188 {%- block search_widget -%}
189 {%- set type = type|default('search') -%}
190 {{ block('form_widget_simple') }}
191 {%- endblock search_widget -%}
192
193 {%- block percent_widget -%}
194 {%- set type = type|default('text') -%}
195 {{ block('form_widget_simple') }} %
196 {%- endblock percent_widget -%}
197
198 {%- block password_widget -%}
199 {%- set type = type|default('password') -%}
200 {{ block('form_widget_simple') }}
201 {%- endblock password_widget -%}
202
203 {%- block hidden_widget -%}
204 {%- set type = type|default('hidden') -%}
205 {{ block('form_widget_simple') }}
206 {%- endblock hidden_widget -%}
207
208 {%- block email_widget -%}
209 {%- set type = type|default('email') -%}
210 {{ block('form_widget_simple') }}
211 {%- endblock email_widget -%}
212
213 {%- block range_widget -%}
214 {% set type = type|default('range') %}
215 {{- block('form_widget_simple') -}}
216 {%- endblock range_widget %}
217
218 {%- block button_widget -%}
219 {%- if label is empty -%}
220 {%- if label_format is not empty -%}
221 {% set label = label_format|replace({
222 '%name%': name,
223 '%id%': id,
224 }) %}
225 {%- elseif label is same as(false) -%}
226 {% set translation_domain = false %}
227 {%- else -%}
228 {% set label = name|humanize %}
229 {%- endif -%}
230 {%- endif -%}
231 <button type="{{ type|default('button') }}" {{ block('button_attributes') }}>{{ translation_domain is same as(false) ? label : label|trans({}, translation_domain) }}</button>
232 {%- endblock button_widget -%}
233
234 {%- block submit_widget -%}
235 {%- set type = type|default('submit') -%}
236 {{ block('button_widget') }}
237 {%- endblock submit_widget -%}
238
239 {%- block reset_widget -%}
240 {%- set type = type|default('reset') -%}
241 {{ block('button_widget') }}
242 {%- endblock reset_widget -%}
243
244 {%- block tel_widget -%}
245 {%- set type = type|default('tel') -%}
246 {{ block('form_widget_simple') }}
247 {%- endblock tel_widget -%}
248
249 {%- block color_widget -%}
250 {%- set type = type|default('color') -%}
251 {{ block('form_widget_simple') }}
252 {%- endblock color_widget -%}
253
254 {# Labels #}
255
256 {%- block form_label -%}
257 {% if label is not same as(false) -%}
258 {% if not compound -%}
259 {% set label_attr = label_attr|merge({'for': id}) %}
260 {%- endif -%}
261 {% if required -%}
262 {% set label_attr = label_attr|merge({'class': (label_attr.class|default('') ~ ' required')|trim}) %}
263 {%- endif -%}
264 {% if label is empty -%}
265 {%- if label_format is not empty -%}
266 {% set label = label_format|replace({
267 '%name%': name,
268 '%id%': id,
269 }) %}
270 {%- else -%}
271 {% set label = name|humanize %}
272 {%- endif -%}
273 {%- endif -%}
274 <{{ element|default('label') }}{% if label_attr %}{% with { attr: label_attr } %}{{ block('attributes') }}{% endwith %}{% endif %}>
275 {%- if translation_domain is same as(false) -%}
276 {%- if label_html is same as(false) -%}
277 {{- label -}}
278 {%- else -%}
279 {{- label|raw -}}
280 {%- endif -%}
281 {%- else -%}
282 {%- if label_html is same as(false) -%}
283 {{- label|trans({}, translation_domain) -}}
284 {%- else -%}
285 {{- label|trans({}, translation_domain)|raw -}}
286 {%- endif -%}
287 {%- endif -%}
288 </{{ element|default('label') }}>
289 {%- endif -%}
290 {%- endblock form_label -%}
291
292 {%- block button_label -%}{%- endblock -%}
293
294 {# Rows #}
295
296 {%- block repeated_row -%}
297 {#
298 No need to render the errors here, as all errors are mapped
299 to the first child (see RepeatedTypeValidatorExtension).
300 #}
301 {{- block('form_rows') -}}
302 {%- endblock repeated_row -%}
303
304 {%- block form_row -%}
305 <div class="row">
306 {{- form_label(form) -}}
307 <div>
308 {{- form_widget(form) -}}
309 {%- if errors|length > 0 -%}
310 <div class="message error">
311 {{- form_errors(form) -}}
312 </div>
313 {%- endif -%}
314 </div>
315 </div>
316 {%- endblock form_row -%}
317
318 {%- block button_row -%}
319 <div>
320 {{- form_widget(form) -}}
321 </div>
322 {%- endblock button_row -%}
323
324 {%- block hidden_row -%}
325 {{ form_widget(form) }}
326 {%- endblock hidden_row -%}
327
328 {# Misc #}
329
330 {%- block form -%}
331 {{ form_start(form) }}
332 {{- form_widget(form) -}}
333 {{ form_end(form) }}
334 {%- endblock form -%}
335
336 {%- block form_start -%}
337 {%- do form.setMethodRendered() -%}
338 {% set method = method|upper %}
339 {%- if method in ["GET", "POST"] -%}
340 {% set form_method = method %}
341 {%- else -%}
342 {% set form_method = "POST" %}
343 {%- endif -%}
344 <form name="{{ name }}" method="{{ form_method|lower }}"{% if action != '' %} action="{{ action }}"{% endif %}{% for attrname, attrvalue in attr %} {{ attrname }}="{{ attrvalue }}"{% endfor %}{% if multipart %} enctype="multipart/form-data"{% endif %}>
345 {%- if form_method != method -%}
346 <input type="hidden" name="_method" value="{{ method }}" />
347 {%- endif -%}
348 {%- if errors|length > 0 -%}
349 <header class="message error">
350 {{- form_errors(form) -}}
351 </header>
352 {%- endif -%}
353 {%- endblock form_start -%}
354
355 {%- block form_end -%}
356 {%- if not render_rest is defined or render_rest -%}
357 {{ form_rest(form) }}
358 {%- endif -%}
359 </form>
360 {%- endblock form_end -%}
361
362 {%- block form_errors -%}
363 {%- if errors|length > 0 -%}
364 <ul>
365 {%- for error in errors -%}
366 <li>{{ error.message }}</li>
367 {%- endfor -%}
368 </ul>
369 {%- endif -%}
370 {%- endblock form_errors -%}
371
372 {%- block form_rest -%}
373 {% for child in form -%}
374 {% if not child.rendered %}
375 {{- form_row(child) -}}
376 {% endif %}
377 {%- endfor -%}
378
379 {% if not form.methodRendered and form is rootform %}
380 {%- do form.setMethodRendered() -%}
381 {% set method = method|upper %}
382 {%- if method in ["GET", "POST"] -%}
383 {% set form_method = method %}
384 {%- else -%}
385 {% set form_method = "POST" %}
386 {%- endif -%}
387
388 {%- if form_method != method -%}
389 <input type="hidden" name="_method" value="{{ method }}" />
390 {%- endif -%}
391 {% endif -%}
392 {% endblock form_rest %}
393
394 {# Support #}
395
396 {%- block form_rows -%}
397 {% for child in form %}
398 {{- form_row(child) -}}
399 {% endfor %}
400 {%- endblock form_rows -%}
401
402 {%- block widget_attributes -%}
403 id="{{ id }}" name="{{ full_name }}"
404 {%- if disabled %} disabled="disabled"{% endif -%}
405 {%- if required %} required="required"{% endif -%}
406 {{ block('attributes') }}
407 {%- endblock widget_attributes -%}
408
409 {%- block widget_container_attributes -%}
410 {%- if id is not empty %}id="{{ id }}"{% endif -%}
411 {{ block('attributes') }}
412 {%- endblock widget_container_attributes -%}
413
414 {%- block button_attributes -%}
415 id="{{ id }}" name="{{ full_name }}"{% if disabled %} disabled="disabled"{% endif -%}
416 {{ block('attributes') }}
417 {%- endblock button_attributes -%}
418
419 {% block attributes -%}
420 {%- for attrname, attrvalue in attr -%}
421 {{- " " -}}
422 {%- if attrname in ['placeholder', 'title'] -%}
423 {{- attrname }}="{{ translation_domain is same as(false) ? attrvalue : attrvalue|trans({}, translation_domain) }}"
424 {%- elseif attrvalue is same as(true) -%}
425 {{- attrname }}="{{ attrname }}"
426 {%- elseif attrvalue is not same as(false) -%}
427 {{- attrname }}="{{ attrvalue }}"
428 {%- endif -%}
429 {%- endfor -%}
430 {%- endblock attributes -%}