8000 [Bridge\Twig] fix bootstrap checkbox_row to render properly & remove … · symfony/symfony@f84749f · GitHub
[go: up one dir, main page]

Skip to content

Commit f84749f

Browse files
arkstefabpot
authored andcommitted
[Bridge\Twig] fix bootstrap checkbox_row to render properly & remove spaceless
1 parent b327a7c commit f84749f

8 files changed

+88
-61
lines changed

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

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,12 @@
88
{# Labels #}
99

1010
{% block form_label -%}
11-
{% spaceless %}
12-
{% if label is same as(false) %}
11+
{%- if label is same as(false) -%}
1312
<div class="{{ block('form_label_class') }}"></div>
14-
{% else %}
15-
{% set label_attr = label_attr|merge({class: (label_attr.class|default('') ~ ' ' ~ block('form_label_class'))|trim}) %}
13+
{%- else -%}
14+
{%- set label_attr = label_attr|merge({class: (label_attr.class|default('') ~ ' ' ~ block('form_label_class'))|trim}) -%}
1615
{{- parent() -}}
17-
{% endif %}
18-
{% endspaceless %}
16+
{%- endif -%}
1917
{%- endblock form_label %}
2018

2119
{% block form_label_class -%}
@@ -35,27 +33,33 @@ col-sm-2
3533
{%- endblock form_row %}
3634

3735
{% block submit_row -%}
38-
{% spaceless %}
39-
<div class="form-group">
40-
<div class="{{ block('form_label_class') }}"></div>
36+
<div class="form-group">{#--#}
37+
<div class="{{ block('form_label_class') }}"></div>{#--#}
4138
<div class="{{ block('form_group_class') }}">
42-
{{ form_widget(form) }}
43-
</div>
39+
{{- form_widget(form) -}}
40+
</div>{#--#}
4441
</div>
45-
{% endspaceless %}
46-
{% endblock submit_row %}
42+
{%- endblock submit_row %}
4743

4844
{% block reset_row -%}
49-
{% spaceless %}
50-
<div class="form-group">
51-
<div class="{{ block('form_label_class') }}"></div>
45+
<div class="form-group">{#--#}
46+
<div class="{{ block('form_label_class') }}"></div>{#--#}
5247
<div class="{{ block('form_group_class') }}">
53-
{{ form_widget(form) }}
54-
</div>
48+
{{- form_widget(form) -}}
49+
</div>{#--#}
5550
</div>
56-
{% endspaceless %}
57-
{% endblock reset_row %}
51+
{%- endblock reset_row %}
5852

5953
{% block form_group_class -%}
6054
col-sm-10
6155
{%- endblock form_group_class %}
56+
57+
{% block checkbox_row -%}
58+
<div class="form-group{% if not valid %} has-error{% endif %}">{#--#}
59+
<div class="{{ block('form_label_class') }}"></div>{#--#}
60+
<div class="{{ block('form_group_class') }}">
61+
{{- form_widget(form) -}}
62+
{{- form_errors(form) -}}
63+
</div>{#--#}
64+
</div>
65+
{%- endblock checkbox_row %}

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

Lines changed: 21 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
{%- endblock form_widget_simple %}
1111

1212
{% block button_widget -%}
13-
{% set attr = attr|merge({class: (attr.class|default('btn-default') ~ ' btn')|trim}) %}
13+
{%- set attr = attr|merge({class: (attr.class|default('btn-default') ~ ' btn')|trim}) -%}
1414
{{- parent() -}}
1515
{%- endblock button_widget %}
1616

@@ -22,18 +22,18 @@
2222
<div class="checkbox">
2323
{{- form_label(form, null, { widget: parent() }) -}}
2424
</div>
25-
{%- endif %}
25+
{%- endif -%}
2626
{%- endblock checkbox_widget %}
2727

2828
{% block radio_widget -%}
2929
{%- set parent_label_class = parent_label_class|default(label_attr.class|default('')) -%}
30-
{% if 'radio-inline' in parent_label_class %}
30+
{%- if 'radio-inline' in parent_label_class -%}
3131
{{- form_label(form, null, { widget: parent() }) -}}
32-
{% else -%}
32+
{%- else -%}
3333
<div class="radio">
3434
{{- form_label(form, null, { widget: parent() }) -}}
3535
</div>
36-
{%- endif %}
36+
{%- endif -%}
3737
{%- endblock radio_widget %}
3838

3939
{# Labels #}
@@ -61,30 +61,30 @@
6161
{{- block('checkbox_radio_label') -}}
6262
{%- endblock radio_label %}
6363

64-
{% block checkbox_radio_label %}
64+
{% block checkbox_radio_label -%}
6565
{# Do not display the label if widget is not defined in order to prevent double label rendering #}
66-
{% if widget is defined %}
67-
{% if required %}
68-
{% set label_attr = label_attr|merge({class: (label_attr.class|default('') ~ ' required')|trim}) %}
69-
{% endif %}
70-
{% if parent_label_class is defined %}
71-
{% set label_attr = label_attr|merge({class: (label_attr.class|default('') ~ ' ' ~ parent_label_class)|trim}) %}
72-
{% endif %}
73-
{% if label is not same as(false) and label is empty %}
66+
{%- if widget is defined -%}
67+
{%- if required -%}
68+
{%- set label_attr = label_attr|merge({class: (label_attr.class|default('') ~ ' required')|trim}) -%}
69+
{%- endif -%}
70+
{%- if parent_label_class is defined -%}
71+
{%- set label_attr = label_attr|merge({class: (label_attr.class|default('') ~ ' ' ~ parent_label_class)|trim}) -%}
72+
{%- endif -%}
73+
{%- if label is not same as(false) and label is empty -%}
7474
{%- if label_format is not empty -%}
75-
{% set label = label_format|replace({
75+
{%- set label = label_format|replace({
7676
'%name%': name,
7777
'%id%': id,
78-
}) %}
78+
}) -%}
7979
{%- else -%}
8080
{% set label = name|humanize %}
8181
{%- endif -%}
82-
{% endif %}
82+
{%- endif -%}
8383
<label{% for attrname, attrvalue in label_attr %} {{ attrname }}="{{ attrvalue }}"{% endfor %}>
8484
{{- widget|raw }} {{ label is not same as(false) ? (translation_domain is same as(false) ? label : label|trans({}, translation_domain)) -}}
8585
</label>
86-
{% endif %}
87-
{% endblock checkbox_radio_label %}
86+
{%- endif -%}
87+
{%- endblock checkbox_radio_label %}
8888

8989
{# Rows #}
9090

@@ -123,15 +123,10 @@
123123
{%- endblock datetime_row %}
124124

125125
{% block checkbox_row -%}
126-
{% spaceless %}
127126
<div class="form-group{% if not valid %} has-error{% endif %}">
128-
<div class="{{ block('form_label_class') }}"></div>
129-
<div class="{{ block('form_group_class') }}">
130-
{{- form_widget(form) -}}
131-
{{- form_errors(form) -}}
132-
</div>
127+
{{- form_widget(form) -}}
128+
{{- form_errors(form) -}}
133129
</div>
134-
{% endspaceless %}
135130
{%- endblock checkbox_row %}
136131

137132
{% block radio_row -%}

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

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,23 +47,33 @@ col-sm-2
4747
{%- endblock fieldset_form_row %}
4848

4949
{% block submit_row -%}
50-
<div class="form-group row">
51-
<div class="{{ block('form_label_class') }}"></div>
50+
<div class="form-group row">{#--#}
51+
<div class="{{ block('form_label_class') }}"></div>{#--#}
5252
<div class="{{ block('form_group_class') }}">
5353
{{- form_widget(form) -}}
54-
</div>
54+
</div>{#--#}
5555
</div>
5656
{%- endblock submit_row %}
5757

5858
{% block reset_row -%}
59-
<div class="form-group row">
60-
<div class="{{ block('form_label_class') }}"></div>
59+
<div class="form-group row">{#--#}
60+
<div class="{{ block('form_label_class') }}"></div>{#--#}
6161
<div class="{{ block('form_group_class') }}">
6262
{{- form_widget(form) -}}
63-
</div>
63+
</div>{#--#}
6464
</div>
6565
{%- endblock reset_row %}
6666

6767
{% block form_group_class -%}
6868
col-sm-10
6969
{%- endblock form_group_class %}
70+
71+
{% block checkbox_row -%}
72+
<div class="form-group row">{#--#}
73+
<div class="{{ block('form_label_class') }}"></div>{#--#}
74+
<div class="{{ block('form_group_class') }}">
75+
{{- form_widget(form) -}}
76+
{{- form_errors(form) -}}
77+
</div>{#--#}
78+
</div>
79+
{%- endblock checkbox_row %}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@
2424
{% block checkbox_widget -%}
2525
{%- set parent_label_class = parent_label_class|default(label_attr.class|default('')) -%}
2626
{%- set attr = attr|merge({class: attr.class|default('form-check-input')}) -%}
27-
{%- if 'checkbox-inline' in parent_label_class -%}
27+
{% if 'checkbox-inline' in parent_label_class %}
2828
{{- form_label(form, null, { widget: parent() }) -}}
29-
{%- else -%}
29+
{% else -%}
3030
<div class="form-check">
3131
{{- form_label(form, null, { widget: parent() }) -}}
3232
</div>

src/Symfony/Bridge/Twig/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"symfony/asset": "~2.8|~3.0|~4.0",
2525
"symfony/dependency-injection": "~2.8|~3.0|~4.0",
2626
"symfony/finder": "~2.8|~3.0|~4.0",
27-
"symfony/form": "~3.4|~4.0",
27+
"symfony/form": "~3.4-beta2|~4.0",
2828
"symfony/http-foundation": "^3.3.11|~4.0",
2929
"symfony/http-kernel": "~3.2|~4.0",
3030
"symfony/polyfill-intl-icu": "~1.0",

src/Symfony/Component/Form/Tests/AbstractBootstrap3HorizontalLayoutTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,4 +154,13 @@ public function testStartTagWithExtraAttributes()
154154

155155
$this->assertSame('<form name="form" method="get" action="http://example.com/directory" class="foobar form-horizontal">', $html);
156156
}
157+
158+
public function testCheckboxRow()
159+
{
160+
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\CheckboxType');
161+
$view = $form->createView();
162+
$html = $this->renderRow($view, array('label' => 'foo'));
163+
164+
$this->assertMatchesXpath($html, '/div[@class="form-group"]/div[@class="col-sm-2" or @class="col-sm-10"]', 2);
165+
}
157166
}

src/Symfony/Component/Form/Tests/AbstractBootstrap4HorizontalLayoutTest.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ public function testLabelOnForm()
2626
$html = $this->renderLabel($view);
2727

2828
$this->assertMatchesXpath($html,
29-
'/label
30-
[@class="col-form-label col-sm-2 form-control-label required"]
29+
'/legend
30+
[@class="col-form-label col-sm-2 col-form-legend required"]
3131
[.="[trans]Name[/trans]"]
3232
'
3333
);
@@ -118,7 +118,7 @@ public function testLegendOnExpandedType()
118118

119119
$this->assertMatchesXpath($html,
120120
'/legend
121-
[@class="col-sm-2 col-form-legend form-control-label required"]
121+
[@class="col-sm-2 col-form-legend required"]
122122
[.="[trans]Custom label[/trans]"]
123123
'
124124
);
@@ -178,4 +178,13 @@ public function testStartTagWithExtraAttributes()
178178

179179
$this->assertSame('<form name="form" method="get" action="http://example.com/directory" class="foobar">', $html);
180180
}
181+
182+
public function testCheckboxRow()
183+
{
184+
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\CheckboxType');
185+
$view = $form->createView();
186+
$html = $this->renderRow($view, array('label' => 'foo'));
187+
188+
$this->assertMatchesXpath($html, '/div[@class="form-group row"]/div[@class="col-sm-2" or @class="col-sm-10"]', 2);
189+
}
181190
}

src/Symfony/Component/Form/Tests/AbstractBootstrap4LayoutTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ public function testLabelOnForm()
2828
$html = $this->renderLabel($view);
2929

3030
$this->assertMatchesXpath($html,
31-
'/label
32-
[@class="form-control-label required"]
31+
'/legend
32+
[@class="col-form-legend required"]
3333
[.="[trans]Name[/trans]"]
3434
'
3535
);
@@ -120,7 +120,7 @@ public function testLegendOnExpandedType()
120120

121121
$this->assertMatchesXpath($html,
122122
'/legend
123-
[@class="col-form-legend form-control-label required"]
123+
[@class="col-form-legend required"]
124124
[.="[trans]Custom label[/trans]"]
125125
'
126126
);

0 commit comments

Comments
 (0)
0