Changeset 2010226
- Timestamp:
- 01/10/2019 09:09:14 PM (7 years ago)
- Location:
- gf-minmax-calculation/trunk
- Files:
-
- 4 edited
-
gravityforms-minmax.js (modified) (2 diffs)
-
gravityforms-minmax.min.js (modified) (1 diff)
-
gravityforms-minmax.php (modified) (2 diffs)
-
readme.txt (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
gf-minmax-calculation/trunk/gravityforms-minmax.js
r2009634 r2010226 1 1 /** 2 2 * Gravity Forms MIN/MAX Calculations 3 * Version 0.3. 03 * Version 0.3.1 4 4 * 5 5 * Add MIN/MAX functions to Gravity Forms calculation … … 47 47 */ 48 48 49 const pattern = /(MIN|MAX)\(([\d\ +\-\*\/\.\,\]+)\s*\)/gi,49 const pattern = /(MIN|MAX)\(([\d\s\W]+)\s*\)/gi, 50 50 matches = fieldFormula.match(pattern); 51 51 52 52 let replaces = []; 53 53 54 54 for(let i in matches) { 55 let components = /(MIN|MAX)\(([\d\ +\-\*\/\.,\]+)\s*\)/gi.exec(matches[i]);55 let components = /(MIN|MAX)\(([\d\s\W]+)\s*\)/gi.exec(matches[i]); 56 56 let values = components[2].split(',').map((value,index,array) => { 57 57 return parseFloat(eval(value.trim())); -
gf-minmax-calculation/trunk/gravityforms-minmax.min.js
r2009634 r2010226 1 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*\)/gi,matches=fieldFormula.match(pattern);let replaces=[];for(let i in matches){let components=/(MIN|MAX)\(([\d\+\-\*\/\.,\]+)\s*\)/gi.exec(matches[i]),values=components[2].split(",").map((value,index,array)=>parseFloat(eval(value.trim())));"MIN"==components[1]&&replaces.push([matches[i],,Math.min(...values)]),"MAX"==components[1]&&replaces.push([matches[i],,Math.max(...values)])}for(let e in replaces)fieldFormula=fieldFormula.replace(replaces[e][0],replaces[e][2]);fieldFormula=fieldFormula.replace(/[^0-9\s\n\r\+\-\*\/\^\(\)\.](MIN|MAX)/g,""),result=eval(fieldFormula)}return result});1 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,matches=fieldFormula.match(pattern);let replaces=[];for(let i in matches){let components=/(MIN|MAX)\(([\d\s\W]+)\s*\)/gi.exec(matches[i]),values=components[2].split(",").map((value,index,array)=>parseFloat(eval(value.trim())));"MIN"==components[1]&&replaces.push([matches[i],,Math.min(...values)]),"MAX"==components[1]&&replaces.push([matches[i],,Math.max(...values)])}for(let e in replaces)fieldFormula=fieldFormula.replace(replaces[e][0],replaces[e][2]);fieldFormula=fieldFormula.replace(/[^0-9\s\n\r\+\-\*\/\^\(\)\.](MIN|MAX)/g,""),result=eval(fieldFormula)}return result}); -
gf-minmax-calculation/trunk/gravityforms-minmax.php
r2009634 r2010226 4 4 * Plugin URI: https://snaptortoise.com?wp-gf-minmax 5 5 * Description: Adds MIN/MAX function support for calculations in number fields 6 * Version: 0.3. 06 * Version: 0.3.1 7 7 * Author: SnapTortoise Web Development 8 8 * Author URI: https://snaptortoise.com … … 29 29 * 30 30 */ 31 $formula = preg_replace( '@[^0-9\s\n\r\ +\-\*\/\^\(\)\.](MIN|MAX)@is', '', $formula );31 $formula = preg_replace( '@[^0-9\s\n\r\s\W](MIN|MAX)@is', '', $formula ); 32 32 33 33 /** 34 34 * Filter just the MIN/MAX function calls within the formula 35 35 */ 36 preg_match_all( '@((MIN|MAX)\(([\d\ +\-\*\/\.\,\]+)\s*\))@is', $formula, $matches );36 preg_match_all( '@((MIN|MAX)\(([\d\s\W]+)\s*\))@is', $formula, $matches ); 37 37 38 38 $search = $matches[0]; -
gf-minmax-calculation/trunk/readme.txt
r2009635 r2010226 32 32 == Changelog == 33 33 34 0.3.1: January 10, 2019 35 36 - Fixes bug where calculations and parantheses within MIN/MAX created errors. 37 38 34 39 0.3.0: January 9, 2019 35 40
Note: See TracChangeset
for help on using the changeset viewer.