Skip to content

Commit 284e1e1

Browse files
georgringerbmack
authored andcommitted
[TASK] Allow floats for TCA type number range values
If the field is using `format=decimal` the range should be allowed to be defined as floats as well. Resolves: #101812 Releases: main, 13.4, 12.4 Change-Id: I64adb0336075dbce333807e8060cd72620693205 Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/85187 Tested-by: core-ci <typo3@b13.com> Reviewed-by: Garvin Hicking <gh@faktor-e.de> Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch> Tested-by: Christian Kuhn <lolli@schwarzbu.ch> Reviewed-by: Benni Mack <benni@typo3.org> Tested-by: Garvin Hicking <gh@faktor-e.de> Tested-by: Benni Mack <benni@typo3.org>
1 parent e4a39fd commit 284e1e1

File tree

4 files changed

+26
-17
lines changed

4 files changed

+26
-17
lines changed

typo3/sysext/backend/Classes/Form/Element/NumberElement.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,8 @@ public function render(): array
188188
$rangeAttributes = [
189189
'type' => 'range',
190190
'class' => 'form-range-input',
191-
'min' => (string)(int)($config['range']['lower'] ?? 0),
192-
'max' => (string)(int)($config['range']['upper'] ?? 10000),
191+
'min' => (string)(float)($config['range']['lower'] ?? 0),
192+
'max' => (string)(float)($config['range']['upper'] ?? 10000),
193193
'step' => (string)($config['slider']['step'] ?? 1),
194194
'style' => 'width: ' . (int)($config['slider']['width'] ?? 400) . 'px',
195195
'title' => (string)$itemValue,
@@ -214,10 +214,10 @@ public function render(): array
214214
$resultArray = $this->mergeChildReturnIntoExistingResult($resultArray, $fieldWizardResult, false);
215215

216216
if (isset($config['range']['lower'])) {
217-
$attributes['min'] = (string)(int)$config['range']['lower'];
217+
$attributes['min'] = (string)(float)$config['range']['lower'];
218218
}
219219
if (isset($config['range']['upper'])) {
220-
$attributes['max'] = (string)(int)$config['range']['upper'];
220+
$attributes['max'] = (string)(float)$config['range']['upper'];
221221
}
222222

223223
if ($format === 'decimal') {

typo3/sysext/core/Classes/DataHandling/DataHandler.php

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1693,11 +1693,20 @@ protected function checkValueForNumber(mixed $value, array $tcaFieldConf): array
16931693

16941694
// Checking range of value:
16951695
if (is_array($tcaFieldConf['range'] ?? false)) {
1696-
if (isset($tcaFieldConf['range']['upper']) && ceil($result['value']) > (int)$tcaFieldConf['range']['upper']) {
1697-
$result['value'] = (int)$tcaFieldConf['range']['upper'];
1698-
}
1699-
if (isset($tcaFieldConf['range']['lower']) && floor($result['value']) < (int)$tcaFieldConf['range']['lower']) {
1700-
$result['value'] = (int)$tcaFieldConf['range']['lower'];
1696+
if ($format === 'decimal') {
1697+
if (isset($tcaFieldConf['range']['upper']) && ceil((float)$result['value']) > (float)$tcaFieldConf['range']['upper']) {
1698+
$result['value'] = (float)$tcaFieldConf['range']['upper'];
1699+
}
1700+
if (isset($tcaFieldConf['range']['lower']) && floor((float)$result['value']) < (float)$tcaFieldConf['range']['lower']) {
1701+
$result['value'] = (float)$tcaFieldConf['range']['lower'];
1702+
}
1703+
} else {
1704+
if (isset($tcaFieldConf['range']['upper']) && ceil($result['value']) > (int)$tcaFieldConf['range']['upper']) {
1705+
$result['value'] = (int)$tcaFieldConf['range']['upper'];
1706+
}
1707+
if (isset($tcaFieldConf['range']['lower']) && floor($result['value']) < (int)$tcaFieldConf['range']['lower']) {
1708+
$result['value'] = (int)$tcaFieldConf['range']['lower'];
1709+
}
17011710
}
17021711
}
17031712

typo3/sysext/core/Tests/Unit/DataHandling/DataHandlerTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ public static function inputValuesRangeDoubleDataProvider(): array
357357
],
358358
'"-0.5" is interpreted correctly as -0.5 but is lower than 0 and set to 0' => [
359359
'-0.5',
360-
0,
360+
0.0,
361361
],
362362
'"0.5" is interpreted correctly as 0.5 and is equal to 0.5' => [
363363
'0.5',
@@ -367,16 +367,16 @@ public static function inputValuesRangeDoubleDataProvider(): array
367367
'39.9',
368368
'39.90',
369369
],
370-
'"42.3" is interpreted correctly as 42.3 but is greater then 42 and set to 42' => [
371-
'42.3',
372-
42,
370+
'"43.3" is interpreted correctly as 43.3 but is greater then 42 and set to 42' => [
371+
'43.3',
372+
42.0,
373373
],
374374
];
375375
}
376376

377377
#[DataProvider('inputValuesRangeDoubleDataProvider')]
378378
#[Test]
379-
public function inputValueCheckRespectsRightLowerAndUpperLimitForDouble(string $value, string|int $expectedReturnValue): void
379+
public function inputValueCheckRespectsRightLowerAndUpperLimitForDouble(string $value, string|int|float $expectedReturnValue): void
380380
{
381381
$tcaFieldConf = [
382382
'type' => 'number',
@@ -392,7 +392,7 @@ public function inputValueCheckRespectsRightLowerAndUpperLimitForDouble(string $
392392

393393
#[DataProvider('inputValuesRangeDoubleDataProvider')]
394394
#[Test]
395-
public function inputValueCheckRespectsRightLowerAndUpperLimitWithDefaultValueForDouble(string $value, string|int $expectedReturnValue): void
395+
public function inputValueCheckRespectsRightLowerAndUpperLimitWithDefaultValueForDouble(string $value, string|int|float $expectedReturnValue): void
396396
{
397397
$tcaFieldConf = [
398398
'type' => 'number',

typo3/sysext/styleguide/Configuration/TCA/tx_styleguide_elements_basic.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -791,8 +791,8 @@
791791
'format' => 'decimal',
792792
'size' => 5,
793793
'range' => [
794-
'lower' => -90,
795-
'upper' => 90,
794+
'lower' => -90.5,
795+
'upper' => 90.5,
796796
],
797797
'default' => 14.5,
798798
'slider' => [

0 commit comments

Comments
 (0)