Group total using javascript

chatequap

New Member
I am trying to find the total of a repeating group of hour total. It is a calc element. I am receiving an error on line 15.

Cannot read property FormElements

requirejs(['fab/fabrik'], function () {
function total() {
// replace 1 with the form's id
var formRef = 'form_2';

// Replace with the element name
var elementName = 'invoices_13_repeat___hour_total';

// The element containing the line items total
var totalElement = 'invoices___total';

var total = 0;

// Get the form's elements
var elements = Fabrik.blocks[formRef].formElements,
v;

// Loop over the elements and if their key contains the elementName update the total
elements.each(function (element, key) {

if (key.contains(elementName)) {
v = element.get('value').toFloat();
if (typeOf(v) !== 'null') {
total += v;
}
}
});



// update the total element
elements.get(totalElement).update(total);
}

// Add events when adding/deleting groups
Fabrik.addEvent('fabrik.form.group.duplicate.end', function (form, event) {
total();
});

Fabrik.addEvent('fabrik.form.group.delete.end', function (form, event) {
total();
});

document.addEvent('blur:relay(input[name^=`invoices_13_repeat___cost_per_hour])', function () {
total();
})
})
 
Last edited:
We are in need of some funding.
More details.

Thank you.

Members online

No members online now.
Back
Top