Forum Replies Created

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter quasibrodo

    (@quasibrodo)

    Hello,

    I was able to activate the advanced settings, and then activate the late load.

    It did not resolve the issue.

    I’m going with Yoast. I don’t have any more time to troubleshoot this.

    Furthermore the whole advanced settings business was mind-boggingly un-intuitive. I’ve been a word-press developer for 5 years and I needed someone to hold my hand to change a setting.

    Thread Starter quasibrodo

    (@quasibrodo)

    Unfortunately the advanced settings tab is not present

    Thread Starter quasibrodo

    (@quasibrodo)

    Hello @salzano

    I’m pretty certain you do in fact have an extra ‘)’.

    Unfortunately the calculation field validation isn’t terribly robust. It’ll miss stuff like this.

    (
    (
    .3 +
    (
    ({Vehicle type:21} * MAX(1,{Vehicle count:94}) ) +
    ({Track License (Price):125.2}*{Track License Quantity:126}) +
    ({Pit License (Price):127.2} * {Pit License Quantity:128}) +
    ({Camp License (Price):129.2} * {Camp License Quantity:130}) +
    ({Extra Chairs: (Price):22.2} * {Extra Chairs: (Quantity):22.3}) +
    ({Extra Tables: (Price):24.2} * {Extra Tables: (Quantity):24.3}) +
    {Extra Power::97} +
    ({Extra Pit Passes: (Price):95.2} * {Quantity:96}) +
    ({Tent quantity:104}*{Tent (Price):103.2}) +
    {Shared Vehicle Fee (Price):87.2}
    )
    )
    * .035
    )
    )//this final parenthesis is extra

    Thread Starter quasibrodo

    (@quasibrodo)

    So I fixed the problem by editing the gravityforms-minmax.js and gravityforms-minmax.min.js

    I changed [\d\s\W]+ to [\d\s\W]+[^)] so it wouldn’t match with extra parentheses.

    I also put the matching and replacing in a while statement so that it would work with nested MIN and MAX functions, such as MAX(MIN(2,3), MIN(4,5))

    Finally instead of indexOf( ‘MIN’ ) I changed it to .indexOf( ‘MIN(‘ ) just so it would be less likely to try to parse incorrectly syntaxed functions.

    /**
    * Gravity Forms MIN/MAX Calculations
    * Version 0.3.1
    *
    * Add MIN/MAX functions to Gravity Forms calculation
    *
    * Thanks to @michaeldozark for gravityforms-exponent plugin:
    * https://github.com/michaeldozark/gravityforms-exponents
    *
    */

    gform.addFilter( ‘gform_calculation_result’, function( result, formulaField, formId, calcObj ) {

    /**
    * Only evaluate if the field has MIN/MAX present
    * Seaching for MIN(/MAX( to be less likely to try parsing incorrectly syntaxed formulae
    *
    * Technically we should be able to run any formulas through this without
    * breaking them, but this way we save some small amount of processing
    *
    * @link https://www.w3schools.com/jsref/jsref_indexof.asp
    * Description of indexOf method
    */

    if ( formulaField.formula.indexOf( ‘MIN(‘ ) > -1 || formulaField.formula.indexOf( ‘MAX(‘ ) > -1 ) {

    /**
    * Replace field tags with their associated values
    *
    * @param int formId The ID of the form in use
    * @param string formula The value of the “Formula” field entered in the form admin
    *
    * We are stripping out anything that is not a number, decimal, space, or simple arithmetical operator.
    * We are excluding any extra nested parenthesis that match might find [^)]
    *
    * @param object formulaField The current calculation field object
    * @var string fieldFormula
    */
    let fieldFormula = calcObj.replaceFieldTags( formId, formulaField.formula, formulaField ), pattern = /(MIN|MAX)\(([\d\s\W]+[^)])\s*\)/gi;

    /**
    * Sanitize the formula in case we have malicious user inputs. This
    * prevents malicious code getting passed to our eval call later in the
    * function
    *
    * @link https://www.w3schools.com/jsref/jsref_replace.asp
    * Description of replace method
    *
    * while is to facilitate parsing nested MIN and MAX functions
    */
    while ( fieldFormula.indexOf( ‘MIN(‘ ) > -1 || fieldFormula.indexOf( ‘MAX(‘ ) > -1 ) {

    let matches = fieldFormula.match(pattern), replaces = [];

    for(let i in matches) {
    let components = /(MIN|MAX)\(([\d\s\W]+[^)])\s*\)/gi.exec(matches[i]);
    let values = components[2].split(‘,’).map((value,index,array) => {
    return parseFloat(eval(value.trim()));
    });

    if (components[1] == “MIN”) replaces.push([matches[i], , Math.min(…values)]);
    if (components[1] == “MAX”) replaces.push([matches[i], , Math.max(…values)]);
    }

    for(let i in replaces) {
    fieldFormula = fieldFormula.replace(replaces[i][0], replaces[i][2]);
    }

    fieldFormula = fieldFormula.replace( /[^0-9\s\n\r\+\-\*\/\^\(\)\.](MIN|MAX)/g, ” );

    }

    /**
    * Set calculation result equal to evaluated string
    *
    * @link https://www.w3schools.com/jsref/jsref_eval.asp
    * Description of eval function
    */

    result = eval(fieldFormula);

    }

    return result;

    } );

    gform.addFilter(‘gform_calculation_result’,function(result,formulaField,formId,calcObj){if(formulaField.formula.indexOf(‘MIN(‘)>-1||formulaField.formula.indexOf(‘MAX(‘)>-1){let fieldFormula=calcObj.replaceFieldTags(formId,formulaField.formula,formulaField),pattern=/(MIN|MAX)\(([\d\s\W]+[^)])\s*\)/gi;while(fieldFormula.indexOf(‘MIN(‘)>-1||fieldFormula.indexOf(‘MAX(‘)>-1){let matches=fieldFormula.match(pattern),replaces=[];for(let i in matches){let components=/(MIN|MAX)\(([\d\s\W]+[^)])\s*\)/gi.exec(matches[i]);let values=components[2].split(‘,’).map((value,index,array)=>{return parseFloat(eval(value.trim()))});if(components[1]==”MIN”)replaces.push([matches[i],,Math.min(…values)]);if(components[1]==”MAX”)replaces.push([matches[i],,Math.max(…values)])}for(let i in replaces){fieldFormula=fieldFormula.replace(replaces[i][0],replaces[i][2])}fieldFormula=fieldFormula.replace(/[^0-9\s\n\r\+\-\*\/\^\(\)\.](MIN|MAX)/g,”)}result=eval(fieldFormula)}return result})

Viewing 4 replies - 1 through 4 (of 4 total)