Conditional Logic Performance Enhancer

Instructions

  1. Install our free Custom Javascript for Gravity Forms plugin.
    Download the plugin here: https://gravitywiz.com/gravity-forms-code-chest/
    
    1. Copy and paste the snippet into the editor of the Custom Javascript for Gravity Forms plugin.

Code

Filename: gpecf-conditional-logic-performance-enhancer.js

/**
 * Gravity Perks // GP eCommerce Fields // Conditional Logic Performance Enhancer
 * https://gravitywiz.com/documentation/gravity-forms-ecommerce-fields
 *
 * Instructions:
 *     1. Install our free Custom Javascript for Gravity Forms plugin.
 *        Download the plugin here: https://gravitywiz.com/gravity-forms-code-chest/
 *     2. Copy and paste the snippet into the editor of the Custom Javascript for Gravity Forms plugin.
 */

/* Debounce Credit: https://davidwalsh.name/javascript-debounce-function */
function gwizDebounce(func, wait, immediate) {
    var timeout;
    return function () {
        var context = this, args = arguments;
        var later = function () {
            timeout = null;
            if (!immediate) func.apply(context, args);
        };
        var callNow = immediate && !timeout;
        clearTimeout(timeout);
        timeout = setTimeout(later, wait);
        if (callNow) func.apply(context, args);
    };
}

$(document).off("gform_post_conditional_logic.gfCalc_{0}".gformFormat(GFFORMID))

$(document).on("gform_post_conditional_logic.gfCalc_{0}".gformFormat(GFFORMID), gwizDebounce(function () {
    var _GFCalc = rgars(window, 'gf_global/gfcalc/{0}'.gformFormat(GFFORMID));
    _GFCalc.runCalcs(formId, _GFCalc.formulaFields);
}, 15));

Leave a Reply

Your email address will not be published. Required fields are marked *

  • Trouble installing this snippet? See our troubleshooting tips.
  • Need to include code? Create a gist and link to it in your comment.
  • Reporting a bug? Provide a URL where this issue can be recreated.

By commenting, I understand that I may receive emails related to Gravity Wiz and can unsubscribe at any time.