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

Problems with removeInstance

OkanaganRick
Registered: Apr 13 2010
Posts: 8
Answered

Good morning, all.
 
My document contains two dynamic subforms. subformA contains a dynamic subform, containing some fields and a button to remove the instance, along with a button to add new instances of the dynamic subform.
 
subformB contains a subform which is created whenever the add button above is clicked. Its contents don't matter to this question.
 
That is, clicking the add button in subformA creates two subforms, one in subformA and one in subformB. This works.
 
But sometimes I need to remove one of the inner subforms from subformA; if I do so, I need to remove the corresponding subform from subformB. Clicking the remove button removes the correct subform from subformA. The index of the subform I want to remove is the same in both subforms.
 
I have tried many statements to remove the subform from subformB. What command should I be using to delete it? I know I need to use removeInstance but I am having a great deal of difficulty in determining the som.

My Product Information:
LiveCycle Designer, Windows
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Accepted Answer
Get the index from A first, then use it to delete both

var nIdx = subformA.dynSubform.index;

subformA._dynSubform.removeInstance(nIdx);
subformB._dynSubform.removeInstance(nIdx);

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

OkanaganRick
Registered: Apr 13 2010
Posts: 8
thomp wrote:
Get the index from A first, then use it to delete bothvar nIdx = subformA.dynSubform.index;

subformA._dynSubform.removeInstance(nIdx);
subformB._dynSubform.removeInstance(nIdx);
Thanks, Thom.

I tried _dynSubform.removeInstance(nIdx) followed by subformB.dynSubform.removeInstance(nIdx) (while I was within dynSubformA) and found that didn't work, but if I exchanged the order of the statements, it did work.

Moral of the story: Don't try shortcuts.