OK, I have two collections, each with two components. I have one section for Revenues and another for Expenses. In each collection, I have two fields.
(1) Single line field to gather account number, format 999-999999-999999-99999. I have added the CSS class: account_number
(2) Currency field to gather the dollar amount to/ from the account, format 999,999,999. I have added the CSS class: revenue_amount and expense_amount.
I have js code that adds all revenue amounts and expense amounts into a total for each item. This works, though isn't formatted. The following js code is what I have:
For formatting:
$.getScript('https://cocatlfs/Forms/js/jquery.mask.min.js',
function () {
$(".phone_number input").mask("999-999-9999");
$(".account_number input").mask("999-999999-999999-99999");
$('.revenue_amount input, .expense_amount input').mask('000,000,000,000', {reverse: true});
});
For totaling each section:
$('.revenue_block').on('blur', 'input', sumRevTotal);
function sumRevTotal() {
var s = 0;
$('.revenue_amount input').each(function () {
s += parseRevNumber($(this).val());
});
$('.revenue_total input').val(s);
}
function parseRevNumber(n) {
var f = parseFloat(n); //Convert to float number.
return isNaN(f) ? 0 : f; //treat invalid input as 0;
};
$('.expense_block').on('blur', 'input', sumExpTotal);
function sumExpTotal() {
var s = 0;
$('.expense_amount input').each(function () {
s += parseExpNumber($(this).val());
});
$('.expense_total input').val(s);
}
function parseExpNumber(n) {
var f = parseFloat(n); //Convert to float number.
return isNaN(f) ? 0 : f; //treat invalid input as 0;
};
The formatting works with the first iteration in the collection, but when a new set of items is added, the formatting does not pick up for either field
I realize that my addition won't work with the commas present in the number, so I will eventually need to clear those to get the math correct, but then I would like to format the total to have the same "000,000,000" format.
I imagine that I am not calling the procedure to do formatting after the second/third/... instance is created.
(Also, on a side note, the currency fields that do format during entry lose formatting once I exit the field. Don't know why it isn't staying. )
Thanks for any help.