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

Please help with instanceManager

JCASE
Registered: May 12 2010
Posts: 29

OK, so I have 2 repeatable subforms. The first one has text fields and drop down fields. I have a addInstance button and when I click it I add a new instance to the 1st subform. But, the 2nd subform is controlled by a yes/no drop down field in the 1st subform. I am having trouble controlling the instance of the 2nd subform with the drop down field. I know it is tough to explain in text, I want to post the sample, but not sure how. Can someone please help me.

I tried if/else on the addInstance button based on the rawValue on the drop down box, but it's not working right. WHat can I do?

My Product Information:
LiveCycle Designer, Windows
JCASE
Registered: May 12 2010
Posts: 29
I published a sample of my work which will better explain the issue I am having with the 2nd subform.

https://acrobat.com/#d=8pJfPJ-FjLaxfvWvNJ6H2Q
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Please explain a bit more. How is an instance of the 2nd subform added? You say it's based on a value in the 1st repeated subforms. Does each 2nd subform depend on a particular 1st subform? Just list the sequence of actions that take place.

Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Then most important JavaScript Development tool in Acrobat
[url=http://www.pdfscripting.com/public/34.cfm#JSIntro][b]The Console Window (Video tutorial)[/b][/url]
[url=http://www.acrobatusers.com/tutorials/2006/javascript_console][b]The Console Window(article)[/b][/url]

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

JCASE
Registered: May 12 2010
Posts: 29
Thanks for the reply. I think the sequence would go like this......

\\The below script is in a button click. It controls both Subforms. (I labeled them Subform1 & Subform2). The dropdown box value controls whether the second Subform is added.var nSubLength = Form1.nodes.length;
var nSubLength = Form2.nodes.length;

var nNumSub = 0;

for (var nCount = 0; nCount < nSubLength; nCount ++) {if (Form1.nodes.item(nCount).className == "subform")
if (Form2.nodes.item(nCount).className == "subform") {
nNumSub = nNumSub + 1;
}
}
if (nNumSub == 10) {
xfa.host.messageBox("The maximum allowable number of subforms is 10. You cannot add any more subforms.", "Warning", 3);
}
if (Form1.Subform1.DropDownBox.rawValue == 1) {
Form1.Subform1.instanceManager.addInstance(1);
Form2.Subform2.instanceManager.addInstance(1);
}else {
Form1.Subform1.instanceManager.addInstance(1);
}\\The textbox in Form2.Subform2 is calculated. the script is............

if (Page1.Data1.Data.Principal.rawValue == 1) {
this.rawValue = Page1.Data1.Data.Name.rawValue;
}
else {
"";
}
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
There are several issues with this script.

1. nSubLength is declared and acquired twice. Is this varialble and loop an attempt to find the number of repeated subforms in subform 1 or 2? If it is then there is a much easier method. The instance manager keeps track of the number of instances.

For example: Form1.Subform1.instanceManager.count

The maximum allowed is also a property of the instance manager.

Form1.Subform1.instanceManager.max


2. The line that tests the drop down

if (Form1.Subform1.DropDownBox.rawValue == 1) {

only references the first repeated subform. Is this your intention?


Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Then most important JavaScript Development tool in Acrobat
[url=http://www.pdfscripting.com/public/34.cfm#JSIntro][b]The Console Window (Video tutorial)[/b][/url]
[url=http://www.acrobatusers.com/tutorials/2006/javascript_console][b]The Console Window(article)[/b][/url]

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

JCASE
Registered: May 12 2010
Posts: 29
Good. I like easier ways. I did set a max in my example, but it is not needed. So, with that said. the button will have the script...

Form1.Subform1.instanceManager.addInstance();
Form2.Subform2.instanceManager.addInstance();


So that is the easy part. To answer the 2nd part....regarding the 1st reference only - that is not my intention. (the main problem I am having really) My intention is to add an instance to the second subform anytime "yes" is selected. whether every other time, everytime, or not at all.

So the First Subform could have 6 instances and the 2nd subform could have 3.

Does that make any sense?

I do understand when you you said my script only referenced the 1st instance...not what I wanted.
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
If you want the selection of a "Yes" from the dropdown to create a new instance of the second subform, then put the addInstance on the change event of the dropdown field.

Do you also want to remove an instance of the second subform if the selection is changed to "No"?

Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Then most important JavaScript Development tool in Acrobat
[url=http://www.pdfscripting.com/public/34.cfm#JSIntro][b]The Console Window (Video tutorial)[/b][/url]
[url=http://www.acrobatusers.com/tutorials/2006/javascript_console][b]The Console Window(article)[/b][/url]

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

JCASE
Registered: May 12 2010
Posts: 29
That wouldn't work for 2 reasons. 1. If I have 6 instances in the first subform and only 2 yes values selected, the rest would be no therefore removing the 2 instances i need in the 2nd subform. #2. If I add an instance on yes. that would add a subform so no showing would be instance 0 & 1, but I only need 0 at this point.I know. the project I am working on is from a specific design I have to work around. I wouldn't set it up like this if I had my way.

In subform1, and instance is always added. In subform2 an instance is only added when "yes" is selected. if "no" is selected. Subform2 does nothing. However, the next instance in the subform1 could be "yes", thus adding another to the 2nd subform.

I thought.. (if) "yes" then add subform2 & subform1 (after clicking the "add" button (else) "no" then only add to subform1 (after clicking the "add" button)I just don't know the right script to use that can add the instances the way I want to.
shahal
Registered: May 3 2007
Posts: 43
I have a form that uses instancemanager with addinstance to add rows of a table. I have a button that looks at the raw data value of a field, within that table, and uses it to populate the "To:" field in MS Outlook.
My problem is that this will work with the field in the first row but not the second row.

How can I make this work?

Thanks.