Cannot call event during blur or update

chatequap

New Member
I have the following code to total a repeating group. It works when add or delete is made, but not when hour_total blurs / updates.

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';
for(var key in Fabrik.blocks) {
formRef = key;
}
var total = 0;

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

// 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();
});

Fabrik.addEvent('fabrik.form.calc.blur', function (form, event) {
total();
});



document.addEvent('blur:relay(input[name^=invoices_13_repeat___hour_total])', function () {
total();
})
})
 
There is no 'fabrik.form.calc.blur' event.

Best way is probably just add a blur JS event to the element within Fabrik itself, which calls your total() function. Then Fabrik will handle the event delegation for calling it.

-- hugh
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top