Skip to content
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

Fix number field #3231

Merged
merged 5 commits into from
Jun 15, 2022
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
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