Skip to content

Commit c1e8ca0

Browse files
committed
Fix hidden currency element with Bootstrap 3 theme
1 parent 5a6e2d7 commit c1e8ca0

File tree

2 files changed

+31
-9
lines changed

2 files changed

+31
-9
lines changed

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

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,21 @@
2020
{%- endblock %}
2121

2222
{% block money_widget -%}
23-
<div class="input-group">
24-
{% set append = money_pattern starts with '{{' %}
25-
{% if not append %}
26-
<span class="input-group-addon">{{ money_pattern|replace({ '{{ widget }}':''}) }}</span>
27-
{% endif %}
23+
{% set prepend = not (money_pattern starts with '{{') %}
24+
{% set append = not (money_pattern ends with '}}') %}
25+
{% if prepend or append %}
26+
<div class="input-group">
27+
{% if prepend %}
28+
<span class="input-group-addon">{{ money_pattern|replace({ '{{ widget }}':''}) }}</span>
29+
{% endif %}
30+
{{- block('form_widget_simple') -}}
31+
{% if append %}
32+
<span class="input-group-addon">{{ money_pattern|replace({ '{{ widget }}':''}) }}</span>
33+
{% endif %}
34+
</div>
35+
{% else %}
2836
{{- block('form_widget_simple') -}}
29-
{% if append %}
30-
<span class="input-group-addon">{{ money_pattern|replace({ '{{ widget }}':''}) }}</span>
31-
{% endif %}
32-
</div>
37+
{% endif %}
3338
{%- endblock money_widget %}
3439

3540
{% block percent_widget -%}

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1899,6 +1899,23 @@ public function testMoney()
18991899
);
19001900
}
19011901

1902+
public function testMoneyWithoutCurrency()
1903+
{
1904+
$form = $this->factory->createNamed('name', 'money', 1234.56, array(
1905+
'currency' => false,
1906+
));
1907+
1908+
$this->assertWidgetMatchesXpath($form->createView(), array('id' => 'my&id', 'attr' => array('class' => 'my&class')),
1909+
'/input
1910+
[@id="my&id"]
1911+
[@type="text"]
1912+
[@name="name"]
1913+
[@class="my&class form-control"]
1914+
[@value="1234.56"]
1915+
'
1916+
);
1917+
}
1918+
19021919
public function testNumber()
19031920
{
19041921
$form = $this->factory->createNamed('name', 'number', 1234.56);

0 commit comments

Comments
 (0)