Starting eForm v2.5.2, we have included a Mathematical Evaluator element using which you can calculate complex formula on the go. Here is a live example of what it would look like.
To get started, please read on.
#1: Using numerical elements:
We provide two options for numerical calculations. One is to assign numeric value to existing element options, while the other is to use a numerical type element.
#1.1: Assign Numeric Values
Starting v2.5.2, numerical values can be added to the options of the following elements
- Multiple Choice Questions > Single Options
- Multiple Choice Questions > Multiple Options
- Multiple Choice Questions > Dropdown Options
- Multiple Choice Questions > Matrix (v3.5)
- Multiple Choice Questions > Matrix Dropdown (v3.5)
- Other Form Elements > Radio Options
- Other Form Elements > Checkbox Options
- Other Form Elements > Dropdown Option
- Other Form Elements > Repeatable (v3.5)
The value you assign on the option’s Numeric attribute will be used for the calculation.
#1.2: Using Numeric Elements
Following numeric elements are available.
- Multiple Choice Questions > Single Slider
- Multiple Choice Questions > Single Range
- Multiple Choice Questions > Spinners
- Multiple Choice Questions > Multiple Grading – Slider Type/Range Type
- Multiple Choice Questions > Star Rating
- Multiple Choice Questions > Scale Rating
- Feedback & Upload > Feedback Small Text
- Feedback & Upload > Mathematical Evaluator
- Other Form Elements > Small Text
- Other Form Elements > Keypad
- Other Form Elements > Single Checkbox
For these elements, either straight numeric values can be entered by the user or the option they choose has a numeric value (like ratings).
For toggle type elements (Toggle and Single Checkbox, under v2.5.4 only) if it is checked, then the value returned is 1, otherwise 0.
F1 :: M0+F2and
F2 :: M9+F1) would produce infinite loop on your browser.
1.3: DateTime Element
Starting version 3.7 eForm can calculate days based on date elements. It is accessible from
- Other Form Elements > Date Picker.
Make sure that the type of the element is set to date only or date and time. Time only isn’t supported.
When you put the field ID of a datepicker element in the evaluator, then it calculates the days since epoch (
January 1 1970 00:00) on the browser. Since local time may vary, it is recommended to use the datepicker for calculating differences between two datepicker elements.
#2: Adding Mathematical Evaluator
Mathematical Evaluator can be found inside Feedback & Upload elements. Simply drag or click on the item to add it to a form container.
Here are the important settings:
- Value Editable By User: If enabled, then an input will be shown where user can edit the value.
- Decimal Precision: Number of digits after decimal points to which the value would be rounded.
- Prefix: HTML before value.
- Suffix: HTML after value.
#2.1: Element Appearance
Starting v3.5 mathematical elements can now have the following appearances.
Simple Appearance. No extra settings are necessary.
Align Right ( Row ): Enable this option to make them appear in a tabular format.
Fancy Appearance: Enable this option to make them appear with a strip. Will override other appearance options.
#3: Mathematical Formula with Notations
The evaluator works on formula which you need to give. The formula can be any proper mathematical formula with special variables to fetch values from one of the supported fields. A sample formula would be
#3.1: Variable Naming
The variable naming rule is as follows. The examples are explained with respect to the variable name
|Keyword||Accepted Characters||No. of Character||Description||Example|
|This indicates the type of the element.
|1+||This indicates the key of the element. Both the type and the key can be found from the form builder itself.||
||1||This indicates if we are going to choose a particular row of an element. This is applicable only for the following elements:
If this is absent for the elements above, then summation of all rows will be considered.
|After row identifier
|1+||The row of the element. It starts from position 0.||
||1||This indicates we are going to choose a particular column of an element. This is applicable for the matrix type & repeatable elements only.
If absent for the elements above, then summation of all columns will be considered.
In case of Single Range & Multiple Grading,
|After column identifier
|1+||The column of the element. It starts from position 0.||
#3.2: Expression Syntax:
The parser accepts a pretty basic grammar. Operators have the normal precidence —
f(x,y,z) (function calls),
% (multiplication, division, and remainder), and finally
|| (addition, subtraction, and string concatenation) — and bind from left to right (yes, even exponentiation… it’s simpler that way).
There’s also a “
,” (comma) operator that concatenates values into an array. It’s mostly useful for passing arguments to functions, since it doesn’t always behave like you would think with regards to multi-dimensional arrays. If the left value is an array, it pushes the right value onto the end of the array, otherwise, it creates a new array “[left, right]“. This makes it impossible to create an array with another array as it’s first element. Function operators
The parser has several built-in “functions” that are actually operators. The only difference from an outside point of view, is that they cannot be called with multiple arguments and they are evaluated by the simplify method if their arguments are constant.
A few examples of valid mathematical evaluators would be
(M1*(20+M6+M5))+(M2*(15+M8))+(M3*12)+(M4*(10+M9))+((M1*(20+M6+M5))+(M2*(15+M8))+(M3*12)+(M4*(10+M9)))*0.125 The one used in our Food Order Form.
(M1+M2)+(M8+M9)+(M10+M11)+(M6+M7*2)+(M3+M4R0*10+M4R1*5+M4R2*20+M5) The one used in our Service Cost Estimator.