4.2 - Calculation fields usage
Calculation fields can be used as simple calculation fields, however they also have the power to run Javascript code based on form changes or a manual button click.
Triggering a Calculation Field
Manual
When selecting Manual, a button will be displayed on the form that the user can tap. This is currently only supported in Forms2/BIC2.
Automatic
If you select automatic, any time a field is changed, the code within this calculation field is run. This can be quite powerful, however it also has the ability to create performance overhead, so be careful when designing automatic code launching. It may be better to use external Javascript and tap into specific field change events using jQuery.
Adding Code to a Calculation Field
To add code to a calculation field, you simply add your javascript within a function like this:
function() { /* your JS code */ }
Things To Consider
Keep It Light
It's best to keep your code as simple as possible within this code box - for example, it is much better to simply use the calculation field to call a function you've defined elsewhere rather than putting all of your code into the code box.
This allows you to keep your code in an easier develop area, as well as means any changes you make to your code don't require you to regenerate for form.
Commenting
When commenting lines of code, keep in mind the code within this box is collapsed to a single line. This means if you use // to comment, this will effectively comment out all of the code after this line.
To add comments, use the comment block option instead: /* my comment */