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

Conversation

julienfalque
Copy link
Contributor

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.

Copy link
Contributor

@ro0NL ro0NL left a comment

Choose a reason for hiding this comment

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

👍 conflicts with #25167

[@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!

{% if not append %}
<span class="input-group-addon">{{ money_pattern|replace({ '{{ widget }}':''}) }}</span>
{% endif %}
{% set append_before = not (money_pattern starts with '{{') %}
Copy link
Contributor

Choose a reason for hiding this comment

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

what about a check like money_pattern is '{{ widget }}' wouldnt that be more concise?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Don't know, a starts with or ends with test would still be required in case the currency symbol must be appended.

Copy link
Contributor

Choose a reason for hiding this comment

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

Right, lets call those variables append + prepend?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@julienfalque julienfalque force-pushed the bootstrap-3-money branch 2 times, most recently from c1e8ca0 to 31f3a4f Compare December 2, 2017 10:29
Copy link
Contributor

@ro0NL ro0NL left a comment

Choose a reason for hiding this comment

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

Nice catch. Perhaps, to close the gates, add 2 more tests in MoneyTypeTest

 $this->assertSame('{{ widget }}', $view->vars['money_pattern']); // currency=false

 $this->assertSame('... {{ widget }}', $view->vars['money_pattern']); // prepended currency

@julienfalque
Copy link
Contributor Author

Tests added.

@fabpot
Copy link
Member

fabpot commented Dec 2, 2017

Do we have the same issue with Bootstrap 4 support?

@julienfalque
Copy link
Contributor Author

It looks like when Bootstrap 4 theme was added, most of the content of the Bootstrap 3 theme was moved to a common file used by both so yes, I think Bootstrap 4 theme has the same issue. Merging this PR up to 3.4 would probably bring conflicts: the patch must be moved to the common file, which will also fix the issue for Bootstrap 4. Same applies with the tests as they use a common base class.

@fabpot
Copy link
Member

fabpot commented Dec 11, 2017

Thank you @julienfalque.

@fabpot fabpot merged commit c5af7fd into symfony:2.7 Dec 11, 2017
fabpot added a commit that referenced this pull request Dec 11, 2017
…rap 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
@julienfalque julienfalque deleted the bootstrap-3-money branch December 11, 2017 22:25
This was referenced Dec 15, 2017
This was referenced Jan 5, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants