Bindings can be used to perform calculations on your form such as calculating the total cost of a selected product and multiplying by the selected quantity, or to increase a total cost value/field based on selected options.
When writing a calculation, you can either write a single line calculation or use conditional logic. A calculation in its simplest form would look like this:
[productcost] * [quantity]
Or you could write a conditional statement:
IF [product] = 'ABC Small Widget' THEN 100 * [quantity] ELSEIF [product] = 'ABC Large Widget' THEN 200 * [quantity] ENDIF
On This Page
- Supported Operators
- Using Bind Values
- Using a Bind Value in a Calculation
- Applying Currency Formatting
- Making the Field Read-Only
- Getting the Total Cost of all Selected Options
You can use any of the following mathematical operators:
|*||Multiplication; for example [productCost] * [quantity]|
|/||Division; for example [perProductCost]=[productCost] /[quantity]|
|( )||Use Parenthesis to group operations together; for example ([subtotal]+[shipping])-[discount]|
In the above example, we're checking which product was selected and executing a calculation based on the selected product. This works when you have only a few products, but gets difficult when you have many products with different prices. Bind Values are values assigned to each option of a Multi Choice Field (CheckBox, Radio or Drop Down) that can be used in a calculation.
The Bind Value field is only used when writing calculations. It is not used when you write the conditions of an IF/THEN/ELSE statement. When writing an IF statement the "Data Value" is used in the comparison.
When a bind value is present it will be automatically used in a calculation. A statement could be written as:
This would use the bind value from the selected option in the product field and multiple it by the quantity.
Currency formatting can be applied to the result of a bind statement by settings the fields mask property to one of the available currency formatting options or using the currencyFormat wildcard Function.
Using The Field Mask Option
If the bind statement is on a field, the easiest option is to use the fields mask setting to apply currency formatting:
Click on the field element on your form or in the form outline panel.
In the Field Properties > Field General Settings panel, find and click the Mask property.
Select the type of currency formatting to apply from the list of available options.
Using the CurrencyFormat Wildcard Function
In the Binding Editor window, highlight the value that you want to format with a currency.
Click the Functions button in the toolbar.
In the window that appears, select the type of currency, and then click Save.
You can apply the currencyFormat() function around a calculation as well as a single field. For example, you can write:
This will format the results of the [product]*[quantity] calculation with currency formatting.
Often, you'll want to make the field that has a binding on it read only. This can be done by changing the fields read-only property to true in the Element Properties Panel.
Consider the scenario where you have, for example, a group of checkboxes, in which each checkbox has a corresponding dollar value. Here's a shortcut to calculating the total cost of all of the selected options. You'll need to assign a bind value to each option, and then use a Wildcard Modifier Function in your bind statement. Do the following:
Ensure each option has a bind value present in the bind column in the Field Values window.
In your binding, insert the wildcard of the field you want to use in the calculation.
Highlight the wildcard and click the Functions button in the toolbar.
Scroll down to the very bottom and select the addSelected() function, and then click OK.
This will wrap the wildcard in the addSelected() function. The result should look something like this:
This will evaluate to the sum of all of the bind values for the selected options. You can use this anywhere within your calculation.