Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Feature: [Form] Toggle Displaying Percent Type Symbol #28797

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

Closed
wants to merge 19 commits into from
Closed

Feature: [Form] Toggle Displaying Percent Type Symbol #28797

wants to merge 19 commits into from

Conversation

d42ohpaz
Copy link

@d42ohpaz d42ohpaz commented Oct 9, 2018

Q A
Branch? master
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #28796
License MIT
Doc PR symfony/symfony-docs#10464

PercentType symbol option

As of this writing, Symfony will forcibly append a percentage sign (%) to all input fields that are of the PercentType form type. This PR will introduce a boolean flag called symbol that, when false, will not display the percentage sign. Each of the default layouts that define percent_widget will respect this option.

By default, this new option will be set to true so that it maintains backward compatibility. The unit tests have been updated where appropriate, and a new unit test has been added (as appropriate).

Copy link
Member

@xabbuh xabbuh left a comment

Choose a reason for hiding this comment

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

This looks quite good so far. I have just left a few comments.

Can we think of use cases where you would want to display another symbol than the percent character (then it could make sense to allow arbitrary strings for this option)?

@@ -19,6 +19,7 @@ CHANGELOG
* Deprecated the `--no-debug` console option, set the "APP_DEBUG"
environment variable to "0" instead.
* Deprecated the `Templating\Helper\TranslatorHelper::transChoice()` method, use the `trans()` one instead with a `%count%` parameter
* Only display `PercentType` percent symbol if the `symbol` option is `true`
Copy link
Member

Choose a reason for hiding this comment

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

I don't think we need a changelog entry for this in the FrameworkBundle.

@@ -106,12 +106,16 @@
{%- endblock dateinterval_widget %}

{% block percent_widget -%}
{% if symbol == true %}
Copy link
Member

Choose a reason for hiding this comment

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

let's shorten this: {% if symbol %} (and everywhere else below too)

Copy link
Member

Choose a reason for hiding this comment

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

It also seems like we need to take whitespace control (i.e. the - character) into account here too.

@@ -7,6 +7,7 @@ CHANGELOG
* add bundle name suggestion on wrongly overridden templates paths
* added `name` argument in `debug:twig` command and changed `filter` argument as `--filter` option
* deprecated the `transchoice` tag and filter, use the `trans` ones instead with a `%count%` parameter
* Update `percent_widget` to consider `symbol` option for `PercentType` when displaying the percent symbol
Copy link
Member

Choose a reason for hiding this comment

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

I don't think we need such an entry in the changelog file of the Twig bridge

@@ -9,6 +9,7 @@ CHANGELOG
* deprecated calling `FormRenderer::searchAndRenderBlock` for fields which were already rendered
* added a cause when a CSRF error has occurred
* deprecated the `scale` option of the `IntegerType`
* add `symbol` to `PercentType` options and make available as `FormView` vars
Copy link
Member

Choose a reason for hiding this comment

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

I would reword this a bit:

added a symbol option to the PercentType that allows to disable the output of the percent character

*/
public function buildView(FormView $view, FormInterface $form, array $options)
{
$view->vars['symbol'] = isset($options['symbol']) ? $options['symbol'] : true;
Copy link
Member

Choose a reason for hiding this comment

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

Can be shortened as the option will always be set:

$view->vars['symbol'] = $options['symbol'];

@xabbuh xabbuh added this to the next milestone Oct 10, 2018
@d42ohpaz
Copy link
Author

Can we think of use cases where you would want to display another symbol than the percent character (then it could make sense to allow arbitrary strings for this option)?

I missed finding this yesterday, but apparently there are a few different versions of a percent symbol:

U+0025 % Percent sign (HTML %) (% in HTML5[24]),
U+2030 ‰ per mille sign (HTML ‰ · ‰),
U+2031 ‱ per ten thousand sign (HTML ‱) a.k.a. basis point, and
U+FF05 % fullwidth percent sign (HTML % · see fullwidth forms)
U+FE6A ﹪ small percent sign (HTML ﹪ · see Small Form Variants)
There is also U+066A ٪ ARABIC PERCENT SIGN (HTML ٪), which has the circles replaced by square dots set on edge, the shape of the digit 0 in Arabic numerals.

And there are icons. Unless others object, I'll update the PR later today to allow arbitrary text or boolean false.

<div class="input-group">
{{- block('form_widget_simple') -}}
<div class="input-group-append">
<span class="input-group-text">%</span>
</div>
</div>
{%- else -%}
{{- block('form_widget_simple') -}}
Copy link
Contributor

Choose a reason for hiding this comment

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

could you please add more indention?

Copy link
Contributor

Choose a reason for hiding this comment

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

Same for the other twig parts

@@ -106,12 +106,16 @@
{%- endblock dateinterval_widget %}

{% block percent_widget -%}
{%- if symbol == true -%}
<div class="input-group">
Copy link
Contributor

Choose a reason for hiding this comment

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

could you please add more indention?

@d42ohpaz
Copy link
Author

As for the failed unit tests, I could use some guidance on how to set up an environment and/or execute the tests so that I can reproduce their failures.

@xabbuh
Copy link
Member

xabbuh commented Nov 1, 2018

@dohpaz42 Sorry, I missed your question. I think https://symfony.com/doc/current/contributing/code/tests.html should provide some useful insights.

@xabbuh
Copy link
Member

xabbuh commented Feb 15, 2019

@9ae8sdf76 Do you think you will be able to finish this pull request?

@fabpot
Copy link
Member

fabpot commented Mar 4, 2019

@xabbuh Can you take over this one?

@OskarStark
Copy link
Contributor

I could overtake this too, I just need to know what’s featurewise missing here?

@fabpot
Copy link
Member

fabpot commented Mar 4, 2019

@OskarStark Thank you. I think it's ok feature-wise. It's more about rebasing/squashing and fixing tests if needed after that.

@OskarStark
Copy link
Contributor

Done in #30433

This one can be closed

@fabpot fabpot closed this Mar 4, 2019
@nicolas-grekas nicolas-grekas modified the milestones: next, 4.3 Apr 30, 2019
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.

6 participants