Data integrity issue: Some number fields change their values during data entry
Overview
On some edit forms, when a number containing a comma is entered into a "number" (float) custom field, validation fails. This is reasonable behaviour if the decimal separator is something other than the comma character. (See related issue regarding validation and decimal separators: #4154)
However, in the re-displayed form, the value is silently changed, with everything after the comma stripped off. For example, "50,995.22" is changed to "50". The user is given another chance to submit the form, and if they don't notice the (incorrect) changed value, that incorrect value will be saved.
Reproduction steps
- Create a custom field extending Activities. Data type: Number.
- Add a new activity. In the number field, enter a number that includes a comma, such as "12,345".
Current behaviour
The first attempt to save the form fails. It is redisplayed. The second attempt succeeds. However, the number field has been changed -- the comma and everything to the right of it has been removed.
Expected behaviour
Even if validation fails, the contents of the number field should not change without the user's intervention.
Environment information
CiviCRM master (5.60)
Notes
This issue happens in Activity edit forms (notably, not Contact edit forms), but it may happen elsewhere too. I haven't tracked it down entirely, but the error seems to happen during the re-rendering of the form: \CRM_Core_QuickForm_Action_Display::renderForm()
. Maybe in the Smarty layer?