From 0b6980c09b884fdc4dfc15c4efca63bf3b5c5f5d Mon Sep 17 00:00:00 2001 From: Iwona Just Date: Tue, 20 Aug 2024 15:15:57 +0100 Subject: [PATCH 1/3] money value can start with a minus --- src/fields/Money.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/fields/Money.php b/src/fields/Money.php index a5c96286953..48a52472d4e 100644 --- a/src/fields/Money.php +++ b/src/fields/Money.php @@ -212,8 +212,8 @@ public function normalizeValue(mixed $value, ?ElementInterface $element): mixed } // Fail-safe if the value is not in the correct format - // Try to normalize the value if there are any non-numeric characters - if (is_string($value) && !preg_match('/^\d+$/', $value)) { + // Try to normalize the value if there are any non-numeric characters (except minus sign at the start) + if (is_string($value) && !preg_match('/^(-?)\d+$/', $value)) { try { $value = MoneyHelper::normalizeString($value); } catch (ParserException) { From 91b3eaec0d3573db03304292efa89a53bd168dc3 Mon Sep 17 00:00:00 2001 From: Iwona Just Date: Tue, 20 Aug 2024 17:51:54 +0100 Subject: [PATCH 2/3] use field's currency as a fallback currency --- src/fields/Money.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/fields/Money.php b/src/fields/Money.php index 48a52472d4e..2d1b5ab1da8 100644 --- a/src/fields/Money.php +++ b/src/fields/Money.php @@ -215,7 +215,7 @@ public function normalizeValue(mixed $value, ?ElementInterface $element): mixed // Try to normalize the value if there are any non-numeric characters (except minus sign at the start) if (is_string($value) && !preg_match('/^(-?)\d+$/', $value)) { try { - $value = MoneyHelper::normalizeString($value); + $value = MoneyHelper::normalizeString($value, new Currency($this->currency)); } catch (ParserException) { // Catch a parse and return appropriately if (isset($this->defaultValue) && $this->isFresh($element)) { From 7ee2761cca6ae29ae0874c83feb9f7fc4f88f5d1 Mon Sep 17 00:00:00 2001 From: brandonkelly Date: Wed, 21 Aug 2024 15:01:05 -0400 Subject: [PATCH 3/3] Release note [ci skip] --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2ad5050ae0c..dfe7347405b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ - Fixed a bug where the “Default Values” Table field setting wasn’t escaping column headings. ([#15552](https://github.com/craftcms/cms/issues/15552)) - Fixed a bug where Craft couldn’t be installed with existing project config files, if any plugins specified their schema version via `composer.json`. ([#15559](https://github.com/craftcms/cms/issues/15559)) - Fixed a bug where Money fields’ min, max, and default values weren’t being set to the correct currency. ([#15565](https://github.com/craftcms/cms/issues/15565), [#15566](https://github.com/craftcms/cms/pull/15566)) +- Fixed a bug where Money fields weren’t handling negative values correctly. ([#15565](https://github.com/craftcms/cms/issues/15565), [#15567](https://github.com/craftcms/cms/pull/15567)) - Fixed a bug where admin tables weren’t displaying disabled statuses. ([#15540](https://github.com/craftcms/cms/pull/15540)) - Fixed a JavaScript error that occurred when adding a row to an editable table that didn’t allow reordering rows. ([#15543](https://github.com/craftcms/cms/issues/15543)) - Fixed an error that occurred when editing an element with a Link field previously set to a URL value, if the field no longer allows URLs. ([#15542](https://github.com/craftcms/cms/issues/15542))