diff --git a/CRM/Core/BAO/CustomField.php b/CRM/Core/BAO/CustomField.php index 24fa5a409b77..ccd21764429d 100644 --- a/CRM/Core/BAO/CustomField.php +++ b/CRM/Core/BAO/CustomField.php @@ -1153,21 +1153,21 @@ public static function addQuickFormElement( case 'Float': if ($field->is_search_range && $search) { - $qf->addRule($elementName . '_from', ts('%1 From must be a number (with or without decimal point).', [1 => $label]), 'numeric'); - $qf->addRule($elementName . '_to', ts('%1 To must be a number (with or without decimal point).', [1 => $label]), 'numeric'); + $qf->addRule($elementName . '_from', ts('%1 From must be a number (with or without decimals).', [1 => $label]), 'numeric'); + $qf->addRule($elementName . '_to', ts('%1 To must be a number (with or without decimals).', [1 => $label]), 'numeric'); } elseif ($widget == 'Text') { - $qf->addRule($elementName, ts('%1 must be a number (with or without decimal point).', [1 => $label]), 'numeric'); + $qf->addRule($elementName, ts('%1 must be a number (with or without decimals).', [1 => $label]), 'numeric'); } break; case 'Money': if ($field->is_search_range && $search) { - $qf->addRule($elementName . '_from', ts('%1 From must in proper money format. (decimal point/comma/space is allowed).', [1 => $label]), 'money'); - $qf->addRule($elementName . '_to', ts('%1 To must in proper money format. (decimal point/comma/space is allowed).', [1 => $label]), 'money'); + $qf->addRule($elementName . '_from', ts('%1 From must in money format (a number with or without decimals, ex: %2).', [1 => $label, 2 => Civi::format()->number(123.98)]), 'money'); + $qf->addRule($elementName . '_to', ts('%1 To must in money format (a number with or without decimals, ex: %2).', [1 => $label, 2 => Civi::format()->number(123.98)]), 'money'); } elseif ($widget == 'Text') { - $qf->addRule($elementName, ts('%1 must be in proper money format. (decimal point/comma/space is allowed).', [1 => $label]), 'money'); + $qf->addRule($elementName, ts('%1 must be in money format (a number with or without decimals, ex: %2).', [1 => $label, 2 => Civi::format()->number(123.98)]), 'money'); } break; @@ -2754,30 +2754,22 @@ public static function validateCustomData($params) { switch ($dataType) { case 'Int': $ruleName = 'integer'; - $errorMsg = ts('%1 must be an integer (whole number).', - [1 => $fieldTitle] - ); + $errorMsg = ts('%1 must be an integer (whole number).', [1 => $fieldTitle]); break; case 'Money': $ruleName = 'money'; - $errorMsg = ts('%1 must in proper money format. (decimal point/comma/space is allowed).', - [1 => $fieldTitle] - ); + $errorMsg = ts('%1 must be in money format (a number with or without decimals, ex: %2).', [1 => $fieldTitle, 2 => Civi::format()->number(123.98)]); break; case 'Float': $ruleName = 'numeric'; - $errorMsg = ts('%1 must be a number (with or without decimal point).', - [1 => $fieldTitle] - ); + $errorMsg = ts('%1 must be a number (with or without decimals).', [1 => $fieldTitle]); break; case 'Link': $ruleName = 'wikiURL'; - $errorMsg = ts('%1 must be valid Website.', - [1 => $fieldTitle] - ); + $errorMsg = ts('%1 must be valid Website.', [1 => $fieldTitle]); break; } diff --git a/CRM/Price/BAO/PriceField.php b/CRM/Price/BAO/PriceField.php index 1b19622a54e2..39803c6d4f6a 100644 --- a/CRM/Price/BAO/PriceField.php +++ b/CRM/Price/BAO/PriceField.php @@ -349,7 +349,7 @@ public static function addQuickFormElement( $type = 'money'; } else { - $message = ts('%1 must be a number (with or without decimal point).', [1 => $label]); + $message = ts('%1 must be a number (with or without decimals).', [1 => $label]); $type = 'numeric'; } // integers will have numeric rule applied to them. diff --git a/tests/phpunit/CRM/Case/Form/CustomDataTest.php b/tests/phpunit/CRM/Case/Form/CustomDataTest.php index 10de0a43712f..437d76691848 100644 --- a/tests/phpunit/CRM/Case/Form/CustomDataTest.php +++ b/tests/phpunit/CRM/Case/Form/CustomDataTest.php @@ -11,10 +11,22 @@ class CRM_Case_Form_CustomDataTest extends CiviCaseTestCase { public function setUp(): void { parent::setUp(); + CRM_Core_I18n::singleton()->setLocale('en_US'); + CRM_Core_Config::singleton()->defaultCurrency = 'USD'; + CRM_Core_Config::singleton()->monetaryThousandSeparator = ','; + CRM_Core_Config::singleton()->monetaryDecimalPoint = '.'; $this->custom_group = $this->customGroupCreate(['extends' => 'Case']); $this->custom_group = $this->custom_group['values'][$this->custom_group['id']]; } + public function tearDown(): void { + parent::tearDown(); + CRM_Core_Config::singleton()->defaultCurrency = 'USD'; + CRM_Core_Config::singleton()->monetaryThousandSeparator = ','; + CRM_Core_Config::singleton()->monetaryDecimalPoint = '.'; + CRM_Core_I18n::singleton()->setLocale('en_US'); + } + /** * Test that changes to custom fields on cases generate the correct details * body for ChangeCustomData. @@ -93,11 +105,6 @@ public function testChangeCustomDataFormattedDetailsLocale(array $input, array $ CRM_Core_Config::singleton()->monetaryDecimalPoint = ','; $this->testChangeCustomDataFormattedDetails($input, $expected); - - CRM_Core_Config::singleton()->defaultCurrency = 'USD'; - CRM_Core_Config::singleton()->monetaryThousandSeparator = ','; - CRM_Core_Config::singleton()->monetaryDecimalPoint = '.'; - CRM_Core_I18n::singleton()->setLocale('en_US'); } /**