Highlighted

Remove all instances of a subform

Avatar

Guest

05-11-2008

Is there a way to remove all instances of a subform with an unknown number of instances?

Replies

Highlighted

pguerett

05-11-2008

You can get the number of instances of a subform by using the instanceManager.count property. Then you can create a for loop and remove them one by one until the loop is exhausted.
Highlighted

JohnBrinkman

06-11-2008

Actually, it's even a bit easier than that. The count property on the instance manager is read/write. To remove all instances of a subform you can code:



instanceManager.count = 0;



John

http://blogs.adobe.com/formfeed/
Highlighted

Avatar

Guest

06-11-2008

So I've combined the two responses at an attempt to remove an unknown number of Instances of several Pages, yet it is not working.

Here's what I have:



var i = 0;



for (i = 37; i--; i<=20) {

var page = String.concat("Page", String(i));

page.instanceManager.count = 0;



}



I also tried FormCalc and got the response "accessor page.instanceManager.count = 0 is unknown" or something like that. What am I missing or what am I doing wrong?
Highlighted

Avatar

Guest

06-11-2008

Excuse the poor syntax in the loop. It should be:



for (i = 37; i>= 20; i--) {

var page = String.concat("Page", String(i));

page.instanceManager.count = 0;

}
Highlighted

JohnBrinkman

06-11-2008

Ian:

It looks like you're not constructing a proper reference to your instance manager. The easy way to do it is to prefix the subform name with an "_". e.g. if your subform is named "detailLine", then the instance manager will be named "_detailLine".

To remove all instances, code:

_detailLine.count = 0;

(No need to use a loop).

If you want to selectively delete subform instances, then reference _detailLine.removeInstance() in a loop.



John

http://blogs.adobe.com/formfeed/
Highlighted

Avatar

Guest

07-11-2008

Thanks John,



The reason I'm using a loop is to stream line the removal/setting the count of several pages, for example Page 2 through 4. Within the loop I concatenate "Page" with String(i) and set it as the variable "page". For some reason this variable is not playing nicely with the instance manager. I am able to get message boxes when I DO NOT attempt to call the instance manager with the variable to read "Page4", "Page3", "Page2" and so on until the loop is exhausted so I know that I'm concatenating correctly. When I place the instance manager in there with the variable the loop does not continue and breaks. And I know that the loop breaks because if I call the message box above my call to the instance manager I get a message box with "Page4" but nothing after that.



Here is exactly what I used:



var i = 0;

for (i = xfa.host.numPages; i >= 20; i--) {



var myPage = String.concat("Page", String(i));

xfa.host.messageBox(myPage);

_myPage.count = 0;



}



Ian