From 82afe6052c48fe20a40cd59428eb7c99301a9de4 Mon Sep 17 00:00:00 2001 From: Xiao Hu Tai Date: Fri, 10 Jun 2022 18:03:44 +0200 Subject: [PATCH 1/5] Fix `min` and `max` for `number` fields --- src/Configuration/Content/FieldType.php | 2 ++ templates/_partials/fields/number.html.twig | 14 +++----------- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/src/Configuration/Content/FieldType.php b/src/Configuration/Content/FieldType.php index 162b489bf..897f79976 100644 --- a/src/Configuration/Content/FieldType.php +++ b/src/Configuration/Content/FieldType.php @@ -54,6 +54,8 @@ protected static function defaults(): Collection 'maxlength' => '', 'autocomplete' => true, 'values' => [], + 'min' => 1, + 'max' => 1000, ]); } diff --git a/templates/_partials/fields/number.html.twig b/templates/_partials/fields/number.html.twig index f87b06090..7f03b21cc 100644 --- a/templates/_partials/fields/number.html.twig +++ b/templates/_partials/fields/number.html.twig @@ -2,18 +2,10 @@ {% 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 mode = field.definition.mode|default('float') %} + {% set min = field.definition.min %} + {% set max = field.definition.max %} - {# set step #} {% if not step|default and field.definition['step'] is defined %} {% set step = field.definition.step %} {% elseif not step|default %} From f271b4544236932bfd93a5a9c912e3bd965fef0f Mon Sep 17 00:00:00 2001 From: Xiao Hu Tai Date: Mon, 13 Jun 2022 08:50:37 +0200 Subject: [PATCH 2/5] Remove `mode` --- templates/_partials/fields/number.html.twig | 22 +++++++-------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/templates/_partials/fields/number.html.twig b/templates/_partials/fields/number.html.twig index 7f03b21cc..3f3ed0c16 100644 --- a/templates/_partials/fields/number.html.twig +++ b/templates/_partials/fields/number.html.twig @@ -2,23 +2,15 @@ {% block field %} - {% set mode = field.definition.mode|default('float') %} + {# --- + Removed `mode` + Note: The difference between `float` and `integer` is useless, + because with `any` it still steps with `1`, whereas you'd + rather want to step with `0.01` for floats. + --- #} {% set min = field.definition.min %} {% set max = field.definition.max %} - - {% 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 %} - {% endif %} + {% set step = field.definition['step']|default(1) %} Date: Mon, 13 Jun 2022 10:50:46 +0200 Subject: [PATCH 3/5] Re-enable mode, because `any` is useful to have --- templates/_partials/fields/number.html.twig | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/templates/_partials/fields/number.html.twig b/templates/_partials/fields/number.html.twig index 3f3ed0c16..2a0155ba7 100644 --- a/templates/_partials/fields/number.html.twig +++ b/templates/_partials/fields/number.html.twig @@ -2,16 +2,18 @@ {% block field %} - {# --- - Removed `mode` - Note: The difference between `float` and `integer` is useless, - because with `any` it still steps with `1`, whereas you'd - rather want to step with `0.01` for floats. - --- #} + {% if not mode|default %} + {% set mode = field.definition.mode|default('float') %} + {% endif %} + {% set min = field.definition.min %} {% set max = field.definition.max %} {% set step = field.definition['step']|default(1) %} + {% if mode == 'float' %} + {% set step = field.definition['step']|default("'any'") %} + {% endif %} + Date: Mon, 13 Jun 2022 12:17:05 +0200 Subject: [PATCH 4/5] Clean up in `number` field --- templates/_partials/fields/number.html.twig | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/templates/_partials/fields/number.html.twig b/templates/_partials/fields/number.html.twig index 2a0155ba7..3b9ab7981 100644 --- a/templates/_partials/fields/number.html.twig +++ b/templates/_partials/fields/number.html.twig @@ -2,14 +2,12 @@ {% block field %} - {% if not mode|default %} - {% set mode = field.definition.mode|default('float') %} - {% 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) %} + {# --- 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 %} From 58ea74b8cc283536df77ccad2e5b2fb29bacaf4d Mon Sep 17 00:00:00 2001 From: Bob den Otter Date: Wed, 15 Jun 2022 16:19:35 +0200 Subject: [PATCH 5/5] Added attributes -> update expected count --- tests/php/Configuration/Parser/ContentTypesParserTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/php/Configuration/Parser/ContentTypesParserTest.php b/tests/php/Configuration/Parser/ContentTypesParserTest.php index 517a23d43..fea619fc5 100644 --- a/tests/php/Configuration/Parser/ContentTypesParserTest.php +++ b/tests/php/Configuration/Parser/ContentTypesParserTest.php @@ -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';