Usage (Custom CSS classes):
- Add a class calculator-value on all your calculator inputs
- Add a unique class on each of your calculator inputs IN ADDITION to calculator-value, example input-1
- NOTE: This class can be named anything, it will be used in your formula(s)
- On your results text, in the Source editor, add a span with a custom data attribute data-formula
- EXAMPLE: <span data-formula="([.input-3]/[.input-1])">0</span>
The data formula will reference the unique classes that you've added to your inputs, and calculate the math. It will handle order of operations and standard math (parenthesis, division, multiplication, subtraction, and addition).
Each of your unique classes will be surrounded by square brackets. You will also need to include the dot before the class name.
v2.5.0
Updates:
Functions:
- pv | usage.: data-formula="pv([.rate], [.nper], [.pmt])" | return present value from 3 inputs
- isSet | usage: data-formula="isSet([.input-1])" | return 0 for 0 values and 1 for all others
v3.0.0
Updates:
- Math.js 10.6.1
- Referencing an input value by it's datafield name is now possible in the formula e.g.: [:Answer01].
- The datafield name needs to be prefixed with : to identify the intent to use a data field and not a classname or ID.
- Referencing an input by it's ID is now possible in the formula e.g.: [#ball_i0itNceeQpEGDgkM0qR9CUg]
- Similar to CSS selectors an ID needs to be prefixed by # to identify the intent to use an ID.
- No calculator CSS class needed anymore
- Added CSS class calculator-transform-value-none to suppress the default transformation behaviour.
- Only available on DROPDOWNS
- By default all input values are processed and tried to be evaluated as a number. If that evaluation fails a 0 is returned. e.g.: Trying to use ABC as a number will fail and return 0. Trying to use 1000 as a number will return 1000.
Functions:
- lookupValue | usage.: data-formula="lookupValue({{KeyValueMap}}, '[:Answer01]')" | returns from a Key Value map the matching value otherwise 0
- Key Value Map is a simple JSON object e.g.:
{
"KeyA": 100,
"KeyB": 200
}
v3.0.1
Updates:
- Fixed a bug with automatic tagging for a live calculator failing for choicesets
v3.0.2
Updates:
- Added eventlistener for ixp-slider:saved
v3.0.3
Updates:
- Fixed bug with data-round attribute not actually rounding to the desired number of decimals