Skip to content

Commit

Permalink
Merge pull request #3231 from xiaohutai/fix/number
Browse files Browse the repository at this point in the history
Fix `number` field
  • Loading branch information
bobdenotter authored Jun 15, 2022
2 parents be2c2e3 + 58ea74b commit bc760bc
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 24 deletions.
2 changes: 2 additions & 0 deletions src/Configuration/Content/FieldType.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ protected static function defaults(): Collection
'maxlength' => '',
'autocomplete' => true,
'values' => [],
'min' => 1,
'max' => 1000,
]);
}

Expand Down
30 changes: 7 additions & 23 deletions templates/_partials/fields/number.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,14 @@

{% block field %}

{# set mode #}
{% if not mode|default %}
{% set mode = field.definition.mode|default('float') %}
{% endif %}

{# set min & max #}
{% if not min|default or max|default %}
{% set min = 0 %}
{% set max = 1000 %}
{% endif %}
{% set min = field.definition.min %}
{% set max = field.definition.max %}
{% set mode = field.definition.mode|default('float') %}
{% set step = field.definition['step']|default(1) %}

{# set step #}
{% if not step|default and field.definition['step'] is defined %}
{% set step = field.definition.step %}
{% elseif not step|default %}
{# default step values #}
{% if mode == 'float' %}
{% set step = "'any'" %}
{% elseif mode == 'integer' %}
{% set step = 1 %}
{% else %}
{# field mode unknown #}
{% set step = 1 %}
{% endif %}
{# --- if the mode is `float` and `step` is not set, use the magical 'any' --- #}
{% if mode == 'float' %}
{% set step = field.definition['step']|default("'any'") %}
{% endif %}

<editor-number
Expand Down
2 changes: 1 addition & 1 deletion tests/php/Configuration/Parser/ContentTypesParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class ContentTypesParserTest extends ParserTestBase

public const AMOUNT_OF_ATTRIBUTES_IN_CONTENT_TYPE = 27;

public const AMOUNT_OF_ATTRIBUTES_IN_FIELD = 29;
public const AMOUNT_OF_ATTRIBUTES_IN_FIELD = 31;

public const ALLOWED_LOCALES = 'en|nl|es|fr|de|pl|it|hu|pt_BR|ja|nb|nn|nl_NL|nl_BE';

Expand Down

0 comments on commit bc760bc

Please sign in to comment.