Skip to content

Commit

Permalink
feature #2374 Add default field for percent type. Fixes #2208. (moynzzz)
Browse files Browse the repository at this point in the history
This PR was merged into the 1.x branch.

Discussion
----------

Add default field for percent type. Fixes #2208.

This PR adds missing percent field template.

This field doesn't depend on format configuration it will use type options if provided to render the value properly. If they aren't provided it will use the defaults of the percent type which are `type = fractional` and `scale = 0`.

Commits
-------

b1d0a1d Add default field for percent type. Fixes #2208.
  • Loading branch information
javiereguiluz committed Oct 2, 2018
2 parents 681f7d4 + b1d0a1d commit 87cd27a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Configuration/TemplateConfigPass.php
Expand Up @@ -52,6 +52,7 @@ class TemplateConfigPass implements ConfigPassInterface
'field_json_array' => '@EasyAdmin/default/field_json_array.html.twig',
'field_integer' => '@EasyAdmin/default/field_integer.html.twig',
'field_object' => '@EasyAdmin/default/field_object.html.twig',
'field_percent' => '@EasyAdmin/default/field_percent.html.twig',
'field_raw' => '@EasyAdmin/default/field_raw.html.twig',
'field_simple_array' => '@EasyAdmin/default/field_simple_array.html.twig',
'field_smallint' => '@EasyAdmin/default/field_smallint.html.twig',
Expand Down
6 changes: 6 additions & 0 deletions src/Resources/views/default/field_percent.html.twig
@@ -0,0 +1,6 @@
{%- set type = field_options.type_options.type|default('fractional') -%}
{%- set scale = field_options.type_options.scale|default(0) -%}
{%- if type == 'fractional' -%}
{%- set value = value * 100 -%}
{%- endif -%}
{{ value|number_format(scale) }}%

0 comments on commit 87cd27a

Please sign in to comment.