Thursday, October 25, 2018

Automatic calculation dependencies

If you have ever worked with a spreadsheet such as Microsoft Excel or Google Sheets, you know that values that depend on each other update automatically when you make changes.

This is also a feature often requested in forms, where you might have calculations such as totals that depend on values entered in other places in the form. Here is an example:

Form with totals
Form with totals

Orbeon Forms has had support for such automated dependencies for a long time,[1] but this wasn’t enabled this by default. Well, better late than never: Orbeon Forms 2018.1 enables such dependencies by default for new forms, and you can use a form setting to change this for your existing forms.

How does this work? In concept, it is simple: at form compilation time, Orbeon Forms goes through all the calculated and initial values formulas you have in your form, and makes what is called a topological sort of the formulas. This determines an evaluation or re-evaluation order for all calculated values. When a value changes in the form, Orbeon Forms knows which formulas to recalculate first so that things show as expected. [2]

The beauty of this is that this works no matter where in the forms the dependent values are: they can be before, after, or between values they depend on. Reordering form fields has no effect on the result of the calculations.

For more details, see the documentation.

We hope you will find this feature of Orbeon Forms 2018.1 useful!

  1. Since Orbeon Forms 4.10.  ↩

  2. The underlying form processor used by Orbeon Forms is based on the XForms standard, which calls for computing such dependencies. The difference here is that Orbeon Forms uses variable references in formulas to compute this dependency order, instead of just references to nodes in an XML data model. But the concept is identical.  ↩

No comments:

Post a Comment