Skip to content

Instantly share code, notes, and snippets.

@tahmid-ul
Created April 21, 2021 19:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tahmid-ul/e5a5d341136d0c130a7287959c1f736a to your computer and use it in GitHub Desktop.
Save tahmid-ul/e5a5d341136d0c130a7287959c1f736a to your computer and use it in GitHub Desktop.
Calculates the sum of the numbers entered in each row of repeater field in Fluent forms
(function($) {
let minus;
$('body').on('click','.js-repeat-buttons',function(){
calculate();
})
function calculate(){
let length = $('table.ff_repeater_table > tbody > tr').length
let plocha = 0;
let strecha = 0;
let ucinnost = 0;
for( let i = 0 ; i < length ; i++){
// data attribute of the fields thats need to be summed
let tempplocha = $('[data-name="repeater_field_0_'+i+'"]').val();
let tempstrecha = $('[data-name="repeater_field_1_'+i+'"]').val();
let tempucinnost = $('[data-name="repeater_field_2_'+i+'"]').val();
let temp1 = parseInt(tempplocha);
let temp2 = parseInt(tempstrecha);
let temp3 = parseInt(tempucinnost);
plocha += Number.isInteger(temp1) ? temp1 : 0
strecha += Number.isInteger(temp2) ? temp2 : 0
ucinnost += Number.isInteger(temp3) ? temp3 : 0
console.log(plocha, "Plocha");
console.log(strecha, "střecha");
console.log(ucinnost, "filtrace");
}
// input to show the sum
$('.repeater_sum').val(plocha * strecha * ucinnost).change();
//selector to cacth remove event
minus = $.find('.repeat-minus')
}
$('body').on('click',minus,function(){
calculate();
})
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment