From 05d76c6e86b1cc9b70ed039a5549c5a5206e950b Mon Sep 17 00:00:00 2001 From: Ken Wong Date: Fri, 27 Sep 2024 07:51:36 +0800 Subject: [PATCH 1/3] Fix number field setter Do data type casting from String to either int or float. --- packages/core/src/FieldTypes/Number.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/packages/core/src/FieldTypes/Number.php b/packages/core/src/FieldTypes/Number.php index df99b1d0c0..a1d0725e6e 100644 --- a/packages/core/src/FieldTypes/Number.php +++ b/packages/core/src/FieldTypes/Number.php @@ -54,6 +54,12 @@ public function setValue($value) throw new FieldTypeException(self::class.' value must be numeric.'); } + if (strpos($value, '.') !== false) { + $value = floatval($value); + } else { + $value = intval($value); + } + $this->value = $value; } From e94c4f48a1f07adcbd39daa1d7c0569626a1cb91 Mon Sep 17 00:00:00 2001 From: Ken Wong Date: Mon, 30 Sep 2024 18:24:33 +0800 Subject: [PATCH 2/3] Simplify the string to number casting --- packages/core/src/FieldTypes/Number.php | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/packages/core/src/FieldTypes/Number.php b/packages/core/src/FieldTypes/Number.php index a1d0725e6e..45d655a3af 100644 --- a/packages/core/src/FieldTypes/Number.php +++ b/packages/core/src/FieldTypes/Number.php @@ -54,13 +54,7 @@ public function setValue($value) throw new FieldTypeException(self::class.' value must be numeric.'); } - if (strpos($value, '.') !== false) { - $value = floatval($value); - } else { - $value = intval($value); - } - - $this->value = $value; + $this->value = $value + 0; } /** From 3b1b6af2fb7e4ee578b6d4c2d6fe0c4b1c3ca25e Mon Sep 17 00:00:00 2001 From: Alec Ritson Date: Mon, 30 Sep 2024 13:04:07 +0100 Subject: [PATCH 3/3] Update Number.php --- packages/core/src/FieldTypes/Number.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/core/src/FieldTypes/Number.php b/packages/core/src/FieldTypes/Number.php index 45d655a3af..067d36522d 100644 --- a/packages/core/src/FieldTypes/Number.php +++ b/packages/core/src/FieldTypes/Number.php @@ -54,7 +54,7 @@ public function setValue($value) throw new FieldTypeException(self::class.' value must be numeric.'); } - $this->value = $value + 0; + $this->value = $value ? $value + 0 : ''; } /**