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
constformattedFormula=formula.replace(/\|([0-9])\|/g,'');// Remove all fallback values from formula (|1|)
48
+
constformulaParts=formula.split('|');// Split formula into parts, an array of fields & fallback values ('field|1| + field2|0|' => ['field', 1, 'field2', 0])
49
+
parser.on('callVariable',(name,done)=>{// Get's called on every variable during calculation
50
+
constvalue=values[name];// Get field value from store
51
+
if(typeofvalue==='undefined'||isNaN(parseFloat(value))){// If value doesn't exist, or isn't a number after parsing
52
+
constfallbackIndex=formulaParts.findIndex(item=>item.endsWith(name));// Get index of field in formula parts
53
+
constfallbackValue=parseFloat(formulaParts[fallbackIndex+1]);// Next to field is the fallback value, hence the + 1
54
+
if(fallbackIndex!==false&&!isNaN(fallbackValue)){// If the fallback value exists, and is a number
55
+
done(fallbackValue);
56
+
}
57
+
}else{
58
+
done(value.replace(',','.'));// The value exists, make sure it's in the correct format to be recognized as a number
0 commit comments