SUM of a repeated group

Hello guys, I have one repeated group in my form and below this group I need to summarize some elements (using AJAX). Based on some googling I have this code in calc element:

Code:
return array_sum($data['table___element_raw']);

Once I save my form, I will get correct sum, but this number must be summarized "on the fly" (AJAX) and if I change one number, I will get 0. After saving is the sum again correct.
 
Last edited:
There is a new element type, 'total', which probably does what you need.

Do a full github update, then a J! "discover", and install & enable the "Fabrik Element - Total" plugin. Change the element type on your calc to 'total', then read the tooltips.

-- hugh
 
There is a new element type, 'total', which probably does what you need.

Do a full github update, then a J! "discover", and install & enable the "Fabrik Element - Total" plugin. Change the element type on your calc to 'total', then read the tooltips.

-- hugh

Thank you Hugh, I had this element already installed, but I forget that I need to make this total of repeating calc elements. As last element in row is calc element calculating final price based on dropdowns, fields and checkbox in this row. This total element plugin works great for fields, but not for calc. Is there any chance how to do a "delay" that total element will "wait" for this calc element? Or any other idea?

Thank you!!!
 
Try with this sample code:
JavaScript:
requirejs(['fab/fabrik'], function() {
    Fabrik.addEvent('fabrik.calc.update', function (element, data) {
        var el = Fabrik.getBlock('form_X').formElements.get('table_name___your_total_element');
        el.element.fireEvent('change', new Event.Mock(el.element, 'change'));
    })
})
 
Try with this sample code:
JavaScript:
requirejs(['fab/fabrik'], function() {
    Fabrik.addEvent('fabrik.calc.update', function (element, data) {
        var el = Fabrik.getBlock('form_X').formElements.get('table_name___your_total_element');
        el.element.fireEvent('change', new Event.Mock(el.element, 'change'));
    })
})

Thank you Startpoint for this script but could you please provide more info? This script must be added to JavaScript part in total element or calc element in repeating group? Javascript event? Javascript action? Thank you
 
I created a js file named form_X.js
write this code in js file:
"requirejs(['fab/fabrik'], function() {
Fabrik.addEvent('fabrik.calc.update', function (element, data) {
var el = Fabrik.getBlock('form_X').formElements.get('table_name___your_total_element');
el.element.fireEvent('change', new Event.Mock(el.element, 'change'));
})
})"
and then uploaded it into folder :components/com_fabrik/js.
Then how to set element to call this function to calculate?
 
You need to replace X in form_X.js with your form id and table_name___your_total_element with your element name.
The code will be run and change your total element if you update every calc element in your form.
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top