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

Cannot call event during blur or update

Discussion in 'Community' started by chatequap, Mar 6, 2019.

  1. chatequap

    chatequap New Member

    Level: Community
    I have the following code to total a repeating group. It works when add or delete is made, but not when hour_total blurs / updates.

    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';
    for(var key in Fabrik.blocks) {
    formRef = key;
    }
    var total = 0;

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

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

    Fabrik.addEvent('fabrik.form.calc.blur', function (form, event) {
    total();
    });



    document.addEvent('blur:relay(input[name^=invoices_13_repeat___hour_total])', function () {
    total();
    })
    })
     
  2. cheesegrits

    cheesegrits Support Gopher Staff Member

    Level: Community
    There is no 'fabrik.form.calc.blur' event.

    Best way is probably just add a blur JS event to the element within Fabrik itself, which calls your total() function. Then Fabrik will handle the event delegation for calling it.

    -- hugh
     
  3. chatequap

    chatequap New Member

    Level: Community
    Thank you. It worked.
     
    cheesegrits likes this.

Share This Page