Calculation Field |
Simfatic Forms has a powerful feature to create online calculators. The 'Calculation field' can do calculations 'on the fly'.
You can provide a formula for the calculation field. The formula can take fields from the form as 'variables'. In addition to all common arithmentic, mathematical operations, a number of in-built functions are also provided.
Creating a calculation fieldFirst, place all the input elements that will be part of the formula. Rename the input elements if required. You will mostly need 'Decimal Number' fields; but you can use other input elements as well (like a general text field, radio button, or a drop down list) Now place a Calculation field on the form. Double-click the calculation field to open the properties of the Field.
Press the 'Edit Formula' button to compose the formula.
The Formula editor contains three parts: a 'Form Fields' box that lists the elements in the form, a keypad for digits & operators and a box that lists all the functions supported in the formula.
Creating complex calculation fieldsIf the calculation is very complex, it will be handy to break the calculation in to several steps.
You can create several calculation fields each calculating a part of the formula. It is possible to make these partial results hidden if required. (check the 'Hidden' check box in the Calculation field's property box).
Using conditions in the formulaIt is possible to use conditions in the calculation field's formula. For example, imagine you want to give 10% discount if the total purchase is above or equal to 1000 dollars.
You can use the function if_else(). The if_else function has three arguments: the condition, 'true part' that will be returned if the condition is true, and 'false part' that will be returned if the condition is false.
We can create a calculation field for the net_amount_to_pay having formula:
perc_of is another handy function to calculate the percentage of a value.
Using radio buttons or a dropdown list in the formulaIt may be required some times to base the calculation on a selection (radio button or drop down list) Ensure that you have provided 'value' for all options in the radio group. If you use the radio group field in the formula, the value of the chosen item will be used. For example, imagine you have different subscription plans each costing 10, 20 or 30('base' group) and 1 5 and 6 ('Add On Group).
The plans are provided as two sets of radio buttons ('Base' and 'AddOns') You can have the 'value' for each option same as the price.
The Calculation field for the Total price can have the formula as:
Since it will take the value of the selection on calculation, the right prices get added to the total.
See Also: How to create an online calculator
Calculation field : function reference
|