Add, Recalculate

Here’s a little something that very important to know when working with dynamic subforms and using their “Instance Managers”:http://blogs.adobe.com/formbuilder/2006/05/instantiating_subforms_at_runt.html (IMs) to add instances of them to a form: New subform instances aren’t automatically incorporated into the form’s calculations!

You would immediately notice this problem if you had a form which calculated a total based on line items which can be added or removed from the form. When you add a new line item using the IM’s _addInstance(bool)_ method, the grand total of, say, the cost of all line items isn’t updated to reflect the data you enter into the new line item. This is because the new line item hasn’t been made part of the form’s set of calculation dependencies and is therefore not accounted for by your “grand total” calculation. As a matter of fact, until a call to xfa.form.recalculate() is made, none of the new instances added will be included in the form’s calculations.

To demonstrate this, I’ve created a sample form which has a “line item” section to which line items can be added. As line items are added and their costs changed, the grand total fields at the bottom calculate the total cost of the order: One grand total field performs its calculation using the FormCalc _SUM_ function and a SOM Expression identifying the collection of fields to total while the other uses the LineItem dynamic subform’s IM object to calculate the grand total. Finally, there’s a check box at the top of the repeating “line item” section which, when checked, will cause the “Add Item” button to execute the xfa.form.recalculate(true) statement after adding a new line item. To see the difference, play around with the form by adding line items with the check box both checked and unchecked.

“Download Sample [zip]”:http://blogs.adobe.com/formbuilder/samples/im/AddRecalculate.zip

*Minimum Requirements:* Designer 7.x, Acrobat 7.x.

2 Responses to Add, Recalculate

  1. Darius says:

    I have question, does is posible to “dynamic hide” fields in Designer 6? (ie. set field presence to invisible and invoke xfa.form.recalculate ? )I tryied this, but it won’t work for me, is there any soluction to do that kind of “dynamic hide/show” fields in designer 6?Thx for any help, and sorry for my bad english…Best regards,Darius

  2. Darius,Unfortunately, dynamic PDFs are required for this functionality and they weren’t introduced until Acrobat 7.0 (and its accompanying version of PDF).Therefore, Designer 6.0 is unable to generate dynamic PDF forms which means that you can’t write forms that have dynamic layouts (like adding/removing subform instances, changing the visibility/appearance of objects, etc.).If you’re an Enterprise customer with a Maintenance and Support agreement, then you should be able to upgrade to Designer 7.0 for free. Otherwise, I’m afraid the Designer 7.1 upgrade is only for those who have Designer 7.0 and therefore you would be forced to purchase a full version of Designer 7.0 or Acrobat Pro 7.x (which includes Designer 7.0).