Created
April 21, 2021 19:48
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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