1. Fabrik 3.9 has been released. If you have updated Joomla to 3.9, this is a required update.
    Dismiss Notice

Group total using javascript

Discussion in 'Community' started by chatequap, Feb 12, 2019.

  1. chatequap

    chatequap New Member

    Level: Community
    I am trying to find the total of a repeating group of hour total. It is a calc element. I am receiving an error on line 15.

    Cannot read property FormElements

    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';

    var total = 0;

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

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

    document.addEvent('blur:relay(input[name^=`invoices_13_repeat___cost_per_hour])', function () {
    total();
    })
    })
     
    Last edited: Feb 13, 2019
  2. chatequap

    chatequap New Member

    Level: Community
    friendly bump
     
  3. chatequap

    chatequap New Member

    Level: Community
    Problem solved
     

Share This Page