You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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);const pattern=/\(?(MIN|MAX)\(([\d\s\W]+)\s*\)/gi;while(fieldFormula[0]==="("&&fieldFormula.slice(-1)===")"){fieldFormula=fieldFormula.substr(1,fieldFormula.length-2)}matches=fieldFormula.match(pattern);let 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});