Open MayerBjoern opened 2 years ago
Hey Björn, thank you for the pull request!
The documentation and the demo include calculations that cross-reference each other, but when testing the demo example, these do not seem to work consistently:
This might be avoidable if there is a clear order of evaluation, so that changes are consistent. If it cannot be avoided, then perhaps it might be better not to allow such dependency "loops".
When submitting the object form for the demo schema without entering a sample name, I get a broken form without the other fields, likely because their conditions aren't all fulfilled. I'm not sure if the conditions
are a good place for something like this which is not related to conditional fields. Perhaps there should be a second property for more generic features like this?
This small features uses the infrastructure for conditions in a different way. The newly added condition is called calculate. It does not hide properties, the spoken logic essentially is: "If properties a and b are set, this property can be filled in automatically based on the values of a and b".
Let's look at a small and simplistic JSON example to explain this further:
Once the user fills in meters and seconds with values, meters per seconds gets automatically filled in. If i fill in mps and meters, seconds will be automatically calculated. This is useful for any sort of numerical data that is correlated but where initially it is not clear what values the user will provide/has measured.
property_names is renamed to the plural here, since it expects an array of other properties. digits is simply the number of decimal places to round the result to formula is obviously the calculation formula and essentially just a wrapper for math.js.evaluate
Linked property names in the formula will be replaced with their respective values before mathematical evaluation.