Batch Membership Form: displayed total incorrect when numbers localized
Overview
Total calculation uses parseFloat which ignores localization settings.
This creates a display issue.
Batch Data Entry for Contributions / Total Amount Entered does not display correctly when localized
Reproduction steps
- Change Thousands and Decimal separators to space and comma
- Changing Default Language has no effect on issue.
- Default Language should determine thousands separator and decimal delimiter (but it doesn't).
- Go to Batch Data Entry for Contributions form
- Enter Number of Items equals 1 and a Total Amount containing a decimal and Save
- On next form, enter the Amount with a decimal
- Total Amount Entered does not show the decimal
Current behaviour
Total Amount Entered is calculated using using JS parseFloat, which ignores localization.
The total does not show any decimal amount, and if the thousands separator is used, is even worse.
For example, in a French locale, 1000,10 & 1000,10 will total to 2000,00
And 1 000,10 & 1 000,10 will total to 2,00
Expected behaviour
The total calculation needs to use a locale aware method.
Suggested solution
Use localized input (parseMoney) and output (formatMoney) functions.
parseMoney replaces parseFloat but needs to be written.
function calculateActualTotal() {
var total = 0;
cj('input[id*="_total_amount"]').each(function () {
if (cj(this).val()) {
total += CRM.parseMoney(cj(this).val());
}
});
cj('.batch-actual-total').html(CRM.formatMoney(total));
}