Skip to content

Commit e4bbd46

Browse files
committed
bug symfony#24802 [TwigBridge] [Bootstrap 4] Fix hidden errors (ostrolucky)
This PR was merged into the 3.4 branch. Discussion ---------- [TwigBridge] [Bootstrap 4] Fix hidden errors | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | symfony#24801 | License | MIT | Doc PR | - Fixes displaying errors for: - Symfony\Component\Form\Extension\Core\Type\BirthdayType - Symfony\Component\Form\Extension\Core\Type\CheckboxType - Symfony\Component\Form\Extension\Core\Type\DateIntervalType - Symfony\Component\Form\Extension\Core\Type\DateTimeType - Symfony\Component\Form\Extension\Core\Type\DateType - Symfony\Component\Form\Extension\Core\Type\FileType - Symfony\Component\Form\Extension\Core\Type\RadioType - Symfony\Component\Form\Extension\Core\Type\TimeType <table> <tr><th>Layout</th><th>Before</th><th>After</th></tr> <tr><td>vertical</td><td valign="top"><img src="https://user-images.githubusercontent.com/496233/32405939-1b4c92c8-c16f-11e7-9b21-8af296aa8d94.png" width="400" alt="less validation errors shown in vertical bs4 layout" /></td> <td valign="top"><img src="https://user-images.githubusercontent.com/496233/32405935-008a3d8c-c16f-11e7-8155-2a51ab55ae9a.png" width="400" alt="more validation errors shown in vertical bs4 layout" /></td> </tr> <tr><td>horizontal</td><td valign="top"><img src="https://user-images.githubusercontent.com/496233/32405984-213b432c-c170-11e7-832a-d94c7f7ddf07.png" width="400" alt="less validation errors shown in bs4 horizontal layout" /></td> <td valign="top"><img src="https://user-images.githubusercontent.com/496233/32406022-bd25bf92-c170-11e7-893d-f071225f8273.png" width="400" alt="more validation errors shown" /></td> </tr> </table> Commits ------- 5810983 Fix displaying errors for bootstrap 4
2 parents 15ed486 + 5810983 commit e4bbd46

File tree

2 files changed

+55
-4
lines changed

2 files changed

+55
-4
lines changed

src/Symfony/Bridge/Twig/Resources/views/Form/bootstrap_4_layout.html.twig

Lines changed: 54 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,54 @@
22

33
{# Widgets #}
44

5+
{% block money_widget -%}
6+
{% if not valid %}
7+
{% set group_class = ' form-control is-invalid' %}
8+
{% set valid = true %}
9+
{% endif %}
10+
{{- parent() -}}
11+
{%- endblock money_widget %}
12+
13+
{% block datetime_widget -%}
14+
{%- if widget != 'single_text' and not valid -%}
15+
{% set attr = attr|merge({class: (attr.class|default('') ~ ' form-control is-invalid')|trim}) -%}
16+
{% set valid = true %}
17+
{%- endif -%}
18+
{{- parent() -}}
19+
{%- endblock datetime_widget %}
20+
21+
{% block date_widget -%}
22+
{%- if widget != 'single_text' and not valid -%}
23+
{% set attr = attr|merge({class: (attr.class|default('') ~ ' form-control is-invalid')|trim}) -%}
24+
{% set valid = true %}
25+
{%- endif -%}
26+
{{- parent() -}}
27+
{%- endblock date_widget %}
28+
29+
{% block time_widget -%}
30+
{%- if widget != 'single_text' and not valid -%}
31+
{% set attr = attr|merge({class: (attr.class|default('') ~ ' form-control is-invalid')|trim}) -%}
32+
{% set valid = true %}
33+
{%- endif -%}
34+
{{- parent() -}}
35+
{%- endblock time_widget %}
36+
37+
{% block dateinterval_widget -%}
38+
{%- if widget != 'single_text' and not valid -%}
39+
{% set attr = attr|merge({class: (attr.class|default('') ~ ' form-control is-invalid')|trim}) -%}
40+
{% set valid = true %}
41+
{%- endif -%}
42+
{{- parent() -}}
43+
{%- endblock dateinterval_widget %}
44+
45+
{% block percent_widget -%}
46+
<div class="input-group{{ not valid ? ' form-control is-invalid' }}">
47+
{% set valid = true %}
48+
{{- block('form_widget_simple') -}}
49+
<span class="input-group-addon">%</span>
50+
</div>
51+
{%- endblock percent_widget %}
52+
553
{% block form_widget_simple -%}
654
{% if type is not defined or type != 'hidden' %}
755
{%- set attr = attr|merge({class: (attr.class|default('') ~ ' form-control' ~ (type|default('') == 'file' ? '-file' : ''))|trim}) -%}
@@ -11,7 +59,7 @@
1159

1260
{%- block widget_attributes -%}
1361
{%- if not valid %}
14-
{% set attr = attr|merge({class: (attr.class|default('') ~ ' is-invalid')|trim}) %}
62+
{% set attr = attr|merge({class: (attr.class|default('') ~ ' form-control is-invalid')|trim}) %}
1563
{% endif -%}
1664
{{ parent() }}
1765
{%- endblock widget_attributes -%}
@@ -27,7 +75,7 @@
2775
{% if 'checkbox-inline' in parent_label_class %}
2876
{{- form_label(form, null, { widget: parent() }) -}}
2977
{% else -%}
30-
<div class="form-check">
78+
<div class="form-check{{ not valid ? ' form-control is-invalid' }}">
3179
{{- form_label(form, null, { widget: parent() }) -}}
3280
</div>
3381
{%- endif -%}
@@ -39,7 +87,7 @@
3987
{%- if 'radio-inline' in parent_label_class -%}
4088
{{- form_label(form, null, { widget: parent() }) -}}
4189
{%- else -%}
42-
<div class="form-check">
90+
<div class="form-check{{ not valid ? ' form-control is-invalid' }}">
4391
{{- form_label(form, null, { widget: parent() }) -}}
4492
</div>
4593
{%- endif -%}
@@ -55,6 +103,9 @@
55103
}) -}}
56104
{% endfor -%}
57105
{%- else -%}
106+
{%- if not valid -%}
107+
{%- set attr = attr|merge({class: (attr.class|default('') ~ ' form-control is-invalid')|trim}) %}
108+
{%- endif -%}
58109
<div {{ block('widget_container_attributes') }}>
59110
{%- for child in form %}
60111
{{- form_widget(child, {

src/Symfony/Bridge/Twig/Resources/views/Form/bootstrap_base_layout.html.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
{%- endblock textarea_widget %}
99

1010
{% block money_widget -%}
11-
<div class="input-group">
11+
<div class="input-group{{ group_class|default('') }}">
1212
{%- set append = money_pattern starts with '{{' -%}
1313
{%- if not append -%}
1414
<span class="input-group-addon">{{ money_pattern|replace({ '{{ widget }}':''}) }}</span>

0 commit comments

Comments
 (0)