8000 [TwigBridge][Form] Fix hidden currency element with Bootstrap 3 theme by julienfalque · Pull Request #25233 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[TwigBridge][Form] Fix hidden currency element with Bootstrap 3 theme #25233

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 11, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,21 @@
{%- endblock %}

{% block money_widget -%}
<div class="input-group">
{% set append = money_pattern starts with '{{' %}
{% if not append %}
<span class="input-group-addon">{{ money_pattern|replace({ '{{ widget }}':''}) }}</span>
{% endif %}
{% set prepend = not (money_pattern starts with '{{') %}
{% set append = not (money_pattern ends with '}}') %}
{% if prepend or append %}
<div class="input-group">
{% if prepend %}
<span class="input-group-addon">{{ money_pattern|replace({ '{{ widget }}':''}) }}</span>
{% endif %}
{{- block('form_widget_simple') -}}
{% if append %}
<span class="input-group-addon">{{ money_pattern|replace({ '{{ widget }}':''}) }}</span>
{% endif %}
</div>
{% else %}
{{- block('form_widget_simple') -}}
{% if append %}
<span class="input-group-addon">{{ money_pattern|replace({ '{{ widget }}':''}) }}</span>
{% endif %}
</div>
{% endif %}
{%- endblock money_widget %}

{% block percent_widget -%}
Expand Down
19 changes: 19 additions & 0 deletions src/Symfony/Component/Form/Tests/AbstractBootstrap3LayoutTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1899,6 +1899,25 @@ public function testMoney()
);
}

public function testMoneyWithoutCurrency()
{
$form = $this->factory->createNamed('name', 'money', 1234.56, array(
'currency' => false,
));

$this->assertWidgetMatchesXpath($form->createView(), array('id' => 'my&id', 'attr' => array('class' => 'my&class')),
'/input
[@id="my&id"]
[@type="text"]
[@name="name"]
[@class="my&class form-control"]
[@value="1234.56"]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this prevent regression also?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What kind of regression do you mean?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if a input-group-addon is rendered again, this xpath would still match no?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, the test still passes if any extra element is rendered, as long as the <input> is at first nesting level. But this actually applies to most of these tests with XPath. This could (should?) probably be improved but in a separate PR IMO. WDYT?

Copy link
Contributor
@ro0NL ro0NL Dec 1, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, but now we just test form_widget_simple again; which is probably already covered in some other test. For this new test i'd expect it to cover the change; no rendering of input addons in case of currency=false.

Or at least not containing a currency symbol in general.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added more predicates.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

[not(preceding-sibling::*)]
[not(following-sibling::*)]
'
);
}

public function testNumber()
{
$form = $this->factory->createNamed('name', 'number', 1234.56);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function testMoneyPatternWorksForYen()
$view = $this->factory->create(static::TESTED_TYPE, null, array('currency' => 'JPY'))
->createView();

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

// https://github.com/symfony/symfony/issues/5458
Expand All @@ -62,4 +62,12 @@ public function testSubmitNull($expected = null, $norm = null, $view = null)
{
parent::testSubmitNull($expected, $norm, '');
}

public function testMoneyPatternWithoutCurrency()
{
$view = $this->factory->create(static::TESTED_TYPE, null, array('currency' => false))
->createView();

$this->assertSame('{{ widget }}', $view->vars['money_pattern']);
}
}
0