10000 bug #25233 [TwigBridge][Form] Fix hidden currency element with Bootst… · symfony/symfony@9ac08e8 · GitHub
[go: up one dir, main page]

Skip to content

Commit 9ac08e8

Browse files
committed
bug #25233 [TwigBridge][Form] Fix hidden currency element with Bootstrap 3 theme (julienfalque)
This PR was merged into the 2.7 branch. Discussion ---------- [TwigBridge][Form] Fix hidden currency element with Bootstrap 3 theme | Q | A | ------------- | --- | Branch? | 2.7 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | - When using a `MoneyType` field, one can pass `currency=false` option to hide the currency symbol. This does not work well when using the Bootstrap 3 theme: the symbol is not displayed but HTML elements that are supposed to contain it are still rendered. Commits ------- c5af7fd Fix hidden currency element with Bootstrap 3 theme
2 parents 891b321 + c5af7fd commit 9ac08e8

File tree

3 files changed

+42
-10
lines changed

3 files changed

+42
-10
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: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1899,6 +1899,25 @@ 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+
[not(preceding-sibling::*)]
1916+
[not(following-sibling::*)]
1917+
'
1918+
);
1919+
}
1920+
19021921
public function testNumber()
19031922
{
19041923
$form = $this->factory->createNamed('name', 'number', 1234.56);

src/Symfony/Component/Form/Tests/Extension/Core/Type/MoneyTypeTest.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public function testMoneyPatternWorksForYen()
4343
$view = $this->factory->create(static::TESTED_TYPE, null, array('currency' => 'JPY'))
4444
->createView();
4545

46-
$this->assertTrue((bool) strstr($view->vars['money_pattern'], '¥'));
46+
$this->assertSame('¥ {{ widget }}', $view->vars['money_pattern']);
4747
}
4848

4949
// https://github.com/symfony/symfony/issues/5458
@@ -62,4 +62,12 @@ public function testSubmitNull($expected = null, $norm = null, $view = null)
6262
{
6363
parent::testSubmitNull($expected, $norm, '');
6464
}
65+
66+
public function testMoneyPatternWithoutCurrency()
67+
{
68+
$view = $this->factory->create(static::TESTED_TYPE, null, array('currency' => false))
69+
->createView();
70+
71+
$this->assertSame('{{ widget }}', $view->vars['money_pattern']);
72+
}
6573
}

0 commit comments

Comments
 (0)
0