Remove, Remerge

There’s a bug currently logged against Acrobat 7.x where removing an instance of a dynamic subform, using the “Instance Manager”:http://blogs.adobe.com/formbuilder/2006/05/instantiating_subforms_at_runt.html (IM)’s _removeInstance(int)_ method, doesn’t cause an update to the IM’s _count_ of currently instantiated subforms.

OK, so maybe that was a little too technical so I’ll try to simplify: In Acrobat 7.x, when you remove an instance of a dynamic subform using the IM’s _removeInstance(int)_ method and then check the number of remaining instances using the _count_ property, the number you’ll get won’t reflect the number that remains.

Adobe is aware of this bug and will hopefully be providing a fix for it in an up-coming release.

Fortunately, there’s a simple work-around (and even if the bug gets fixed in a future release, you should probably be checking the version of Acrobat that’s running your form to determine whether you need to be using the work-around or not):

bc.. _DynamicSubformInstanceManager.removeInstance(3);

// Force a remerge of the form’s current data set with its template
// to cause an update to the “count” property of all IMs
xfa.form.remerge();


Calling the Form object’s _remerge()_ method will “force the remerging of the data model and template model to re-create the form model”, as explained in the “Adobe XML Form Object Model Reference”:http://www.adobe.com/devnet/livecycle/designing_forms.html. This means that the form’s *current* data set will be remerged with the template (the form objects like dynamic subforms, fields, etc.). The result will be a form that looks exactly the same as it did in its state just prior to calling xfa.form.remerge() but with all IMs properly updated to the current number of dynamic subforms which they’re managing, thus correctly updating each IM’s _count_ property.Even if this problem is addressed in a future release, you’ll want to check the version of Acrobat that’s running your form in order to know whether it has the fix or not (in JavaScript as follows):bc.. // get the host’s version as a string and split it into an arrayvar oVerArray = xfa.host.version.split(“.”);if (oVerArray[0] == “7″)xfa.form.remerge();p. Or more simply:bc.. if (xfa.host.version.split(“.”)[0] == “7″)xfa.form.remerge();