Hi, I have a problem to show in a field the total of other fields which are in a repetable group. here's my code and the error that I get on change numbers in repetable groups : "el is not defined"
My code :
The image of my form is joined too.
Can anyone help me please. Thanks!!!
My code :
JavaScript:
// JavaScript Document
requirejs(['fab/fabrik'], function() {
function total(el) {
// use form_X where X is your numeric form ID
var form = Fabrik.getBlock('form_48');
// get the object we want to summarize in the 2nd group
var rnum = el.getRepeatNum();
var elLignName = 'data_reac_trainings_80_repeat___hour_' + rnum;
var elLignVal = this.formElements.get(elLignName).getValue();
// replace 17 with your numeric group ID for the repat group
var repeats = form.repeatGroupMarkers[80]
var hourTot = 0;
for (c = 0; c < repeats; c++) {
// replace foo_repeat___whatever_ with the relevant element names in the repeat group, but keep the appended _
//get repetable object
var elObjectName = 'data_reac_trainings_80_repeat___hour_' + c;
//get repetable object value
var elObjectVal = form.formElements.get(elObjectName).getValue();
if (elObjectVal != '') {
var elHourVal = elObjectVal;
hourTot += elHourVal.toFloat();
}
}
// replace foo___total_price with the element name
form.formElements.get('data_reac_trainings___hours_total').update(hourTot.toString());
}
// Add events when adding/deleting groups
Fabrik.addEvent('fabrik.form.group.duplicate.end', function(form, event) {
total(el);
});
Fabrik.addEvent('fabrik.form.group.delete.end', function(form, event) {
total(el);
});
document.addEvent('blur:relay(input[name^=data_reac_trainings_80_repeat___hour])', function() {
total(el);
})
})
Can anyone help me please. Thanks!!!