Skip to content

Commit

Permalink
Tweak money/numeric error messages to not mention point (could be a c…
Browse files Browse the repository at this point in the history
…omma)
  • Loading branch information
mlutfy committed Oct 24, 2023
1 parent 7174f3a commit 642317b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 24 deletions.
28 changes: 10 additions & 18 deletions CRM/Core/BAO/CustomField.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion CRM/Price/BAO/PriceField.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
17 changes: 12 additions & 5 deletions tests/phpunit/CRM/Case/Form/CustomDataTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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');
}

/**
Expand Down

0 comments on commit 642317b

Please sign in to comment.