These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Remove Generated Cells In Order of Last Added

vargs
Registered: Jul 2 2010
Posts: 26

Hello,
 
I have the following button that when pressed, generates a duplicate box of information.
The button contains the following code:
**********************************
 
form1.omtrform.staticpage2.Button2::click - (FormCalc, client)
form1.Row.instanceManager.addInstance(1);
  
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
I then created a "remove" button with the following code.
 
****************************************
form1.Row.instanceManager.removeInstance(1);
 
******************************************
 
The problem with this remove button is that it removes the first box of info that you added. I would like to change this "remove" button to remove the last item that has been added to the form.
 
Thanks,
-Vargs

My Product Information:
LiveCycle Designer, Windows
Niall
Expert
Registered: Apr 26 2006
Posts: 62
Hi Vargs,

When using addInstance the parameter "1" refers to true. This means that the new instance is merged with the data model.

However when using removeInstance, the parameter refers to the instance that you want to remove. The instances use a zero-numbering system, so the first instance is Row[0], then Row[1], Row[2], etc.

The easiest way is to have the remove button in the row, so that the script in the click event can refer to the rows instance.

form1.Row.instanceManager.removeInstance(this.parent.index);

There is an example here: http://www.assuredynamics.com/index.php/category/portfolio/building-dynamic-tables/

In the example you want to have a look at Table 5 (using tables) or Table 6 (using subforms).

If the button is external to the row, then you can still script the button to remove the last instance. In this case you first need to count the number of instances and then delete the last instance.

// count the number of instances
// subtract 1 to get back to a zero-numbered basis
var nRows = form1.Row.instanceManager.count - 1;
form1.Row.instanceManager.removeInstance(nRows);

The above script would go in the click event of a button outside of the repeating object (row).



Hope this helps,

Niall
Assure Dynamics

vargs
Registered: Jul 2 2010
Posts: 26
Thanks so much Niall.
I put the button under Row and added in the code and it worked perfectly.

I appreciate your help.

-vargs