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

Popup Menus populates Image Field

CPearson
Registered: May 20 2008
Posts: 16
Answered

I have worked on a form that display images based on a dropdown list selection, I found the way to do this by using a the following code. // Code written by Tim Huff - Business Development Manager for Acrobat Oct 5 2007
// Populate a variable (sNewValue) with the Current Value of the Drop-down list using the newText event.
var sNewValue = $.boundItem(xfa.event.newText) TextField1.rawValue = sNewValue; // Fill the Text box with what you got
// Test your variable agaist the name of the Image Object. The names for each Image object is listed under the Image
if (sNewValue == "Acrobat Logo") then
//Let's hide the Acrobat Logo
AcrobatLogo.presence = "invisible";
AcrobatPro.presence = "visible";
AcrobatPro.presence = "visible";
endif
This worked fine but I then realized that I needed a multi step dropdown, I found this code here which uses a popup menu: http://www.acrobatusers.com/tutorials/popup-menus-acrobat Is there a way that I can use a popup menu like this in livecycle? This is using AcroForm ? The script would perform the following, User clicks on a item The popup window would display, user would then drill down tree steps lick in the example then the your would select his choice which would intern populate a field the choice image would then show up in the box.

thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Yes, even though the code presented in the article is for an AcroForm, it will work as is for a LiveCycle form. But you have to convert your script to JavaScript. The script you show above is FormCalc.

The LiveCycle JavaScript model is a sub-model of the full Acrobat DOM. The "app" object is at the top of this model so everything in the "app" object works in a LiveCycle form.

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

CPearson
Registered: May 20 2008
Posts: 16
Thanks Thomp,
I have converted the AcroForm to Java and where it says this.getfield reports an error saying that it is not a function. The Text field that normally populates is not working. Once we do get this to populate how do we then get the image to appear do I have to convert the FormCalc to java also?

Thanks so much for your help with this.
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
"getField()" is an AcroForm function. It can't be used in this script. The only thing you need to change in your existing script is the syntax of the "if" and add in the popup menu.

Something like this:
// Display popup menuvar sNewValue= app.popUpMenu(...); // copy seletected value into text fieldTextField1.rawValue = sNewValue; // Select image to displayif(sNewValue == "ImageSelect1"){ImageSelect1.presence = "visible";ImageSelect2.presence = "invisible";ImageSelect3.presence = "invisible";}...etc...

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

CPearson
Registered: May 20 2008
Posts: 16
Your Awesome Thomp, Your suggestion is working great, I am able to populate the text field with the snewvalue and make the photo appear, however I now have another problem. At the bottom of my row I have added a add row button. The button works fine it adds that row, but my data from my selection from the SnewValue is going in my row above not in its new row. Any Suggestion for this fix?
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
I don't know how your dropdown and images fit into the repeatable subform/table on your form. You just said "At the bottom of my row I have added a add row button" without explaining anything. like What row? And what does this have to do with the previous issue?

However, new instances of a subform, and the contained fields are always fresh. They appear as they have been initialized. If you want something to appear in the new row then there has to be some special code to do it.

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

CPearson
Registered: May 20 2008
Posts: 16
Sorry about that Thomp, I really did not give you any information to work with. Here is the problem and I am sure there is a simple fix to this. I have created a Form with the following code.
var aMetro = ["Metro","680 Fixed","680 Tilt N Turn","680 Casement",["Doors","680 Terrace Door"]];
var aFire = ["Fire","FR55 Series","FR4700 Series","6000 Series","7600 Series",["7650TSH","7650TSH 1 over 1","7650TSH 2 over 2","7650TSH 3 over 3","7650TSH 4 over 4","7650TSH 6 over 6","7650TSH 8 over 8",]
,"7650TDH","SCA7650TDH","8600 Series"]
var sNewValue= app.popUpMenu(aFire, aMetro)
Subform2.Table1.Row1.Item.rawValue = sNewValue;
if(sNewValue == "7650TSH 1 over 1"){

Subform2.Table1.Row1.ConfigSubfrom.single.presence = "visible";
Subform2.Table1.Row1.ConfigSubfrom.singletwo.presence = "invisible"; }
else if(sNewValue == "7650TSH 2 over 2"){

Subform2.Table1.Row1.ConfigSubfrom.singletwo.presence = "visible";
Subform2.Table1.Row1.ConfigSubfrom.single.presence = "invisible"; }

My problem is when I use the Table1._Row1.addInstance(1); button, The sNewVale is pointing to Subform2.Table1.Row1.Item.rawValue = sNewValue; and my new row will not receive my data. Should I be adding the form field in order to maintain the ability for the data to be sent to the new instance raw?
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
This code is where? in the Add Instance button?, in a field in the row?

The problem, or limitation with the script is that all the field references are hard coded. If you want the code to affect the fields in a specific row, then it has to be written to affect that spcific row. But how you do this all depends on where the code is located. If it is on a field in the same row as the other fields you want to affect, then the SOM references need to be shortened to be relative references within the row. If the code is outside the table, then it needs to resolve the specific subform it needs to affect and reference that.

For example, the addInstance function returns the subform instance that was just added.

You'll find the answers in this video:
https://admin.adobe.acrobat.com/_a200985228/p87746471/

There's also tons of way more detailed tutorials and examples on exactly this topic at www.pdfscripting.com

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

CPearson
Registered: May 20 2008
Posts: 16
The Code is on a button by itself in the subform, The Add instance button is also in the same subform but below the Code button. The tble which contains the snewvalue is right above the two buttons. all of this is inside of a flow subform.
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
There are two options for getting the new subform instance. The easiest is to always use the last added row. A more sophisticated method is to save a pointer to the last added instance somewhere your script can get to it.

To get the last row in the list use "Table1._Row1.count -1"

To save the last added instance, assign the return value from addInstance to a member variable on the button object that contains the add instance script, like this

this.lastRow = Table1._Row1.addInstance();

This use this member variable in the script instead of the hard coded path.

And be sure to watch that video

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

CPearson
Registered: May 20 2008
Posts: 16
I really do thank you for sticking with me on this, I really do usually pickup on these thing quickly but for some reason I am not getting it. I have watched the video that you sent and it was well done I thank you for that, however when I create a new row and when I add the item in from the popup list my information still goes into the first row not in the new row that was just created. I have added the code that you sent this.lastRow = Table1._Row1.addInstance(); to the add row button which you will see below in the photos. I see that the repeat subform check box is grayed out I can not check it. Please take a look at these photos so that you may be clear on my situation.

http://s943.photobucket.com/albums/ad272/optimum28/
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
I think that one of the first points I make in the video is that all elements in the hierarchy need to have sensible names.

Looking at the photos, the references to "ConfigSubfrom" are all fixed.

The SOM path:
Subform2.Table1.Row1.ConfigSubfrom.single

Where "Row1" is the repeatable subform, does not include an instance reference. By default it references the first instance of "Row1". To reference a different instance, the specific instance node has to be found a different way. One method is to use the "resolveNodes()" function.

Another method is to use the data saved from the "addInstance()" call. Say that the button is called "AddRow", then the data saved from adding a row would be referenced by

AddRow.lastRow;

And then the SOM path I used above would be:
AddRow.lastRow.ConfigSubfrom.single;

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

CPearson
Registered: May 20 2008
Posts: 16
Mr. Thomp, I must thank you again for all of your help with this, you really have answered more than just one question for me it’s more like 4 or 5 you should get the credit for that. I have come to the conclusion with your great help of course that the button that I made that adds products to the form used the snewvalue and pointed to a specific table in the subform. When the add row button is clicked it adds another just like it suppose to with all of the attributes of its original, therefore pointing the data input to original location. I think I will have to rework this form so that the information can point and follow the new row that has been created, If the entire subform was copied and moved the location reference would be the same. If I copy that subform by using the control key while clicking and dragging the form and placing another instance of it on to the form, the form acts independent and the information flows in both locations independently. When I point the add row button to the subform itself the error tell me the element [max] has violated its allowable number of occurrences. I’m sure it’s something that I’m missing, I won’t give up too close to stop now.
CPearson
Registered: May 20 2008
Posts: 16
I got it with all of your help, thanks so much. I had to wrap the form into a repeatable subform of its own then point to that subform for add row. This is great stuff!!!!

Thanks again for all of your great help


Chris