Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.
SOLVED

New to LiveCycle. Need help with Drop-Down Lists.

Avatar

Level 1

I have just started to play with LiveCycle making PDF forms.  One thing I am wondering if it is possible to do is linking available selections in drop down lists.  For example, on a form with a single question on it I have 5 possible answers such as "Rank your favorite fruits in order from most liked to least liked".  Then I have a series of 5 drop down list boxes with the first box containing "Apple, Pear, Peach, Strawberry, Grape".  Is it possible to have someone make a selection in the first box, their favorite fruit on the list, and then the second box would only have four options to choose from?  Say if apple was their favorite, only pear, peach, strawberry and grape would be choosable?  I've tried to find an answer but I'm afraid I don't know enough about the abilities of LiveCycle and/or how to work with scripts (i think that is what I'm seeing people using).  If anybody could take the time to try and push me through this, I would sure appreciate it.

1 Accepted Solution

Avatar

Correct answer by
Former Community Member

Here is an updated form. I had to get help from one of my programmer friends so it involves some sophosticated code. I used a script object to keep the volume of code down.

Have a look and let me know what you think.

Paul

View solution in original post

14 Replies

Avatar

Former Community Member

Yes it is possible ....here is a sample that shows it. The code on the DD os on the Exit event and I added a reset button in case the user wants to start the question again.

Paul

Avatar

Level 1

Paul,

That works really good as long as they are selected in order.  I have two questions:

1-How did you set this up?  Is it something that you can explain to a noob like me?

2-I noticed that if you work backwards, the drop downs don't update.  For example, if strawberry is the favorite and then pear is selected as the least favorite, boxes 2-4 do not have strawberry but do contain pear.  Is this a one way street or is it just something that can be adjusted?

Avatar

Former Community Member

It can be adjusted .....I only did it in the one direction to show how. You would have to add the code to each DD to update all of the others. So each dropdown will have 4 statements (to update the other 4 dropdowns).

The secret is in setting up each dropdown to have the same order in the dropdown. Then you can delete the item that is selected from all of the others.

Paul

Avatar

Level 1

Okay.  Bear with me here.  What I would need to adjust is the code (for DD1) such as:

DD2.deleteItem(DD1.selectedIndex)

DD3.deleteItem(DD1.selectedIndex)

DD4.deleteItem(DD1.selectedIndex)

DD5.deleteItem(DD1.selectedIndex)

Correct?

Would it need to look something like:

DD2.deleteItem(DD1.selectedIndex)

DD3.deleteItem(DD1.selectedIndex)

DD4.deleteItem(DD1.selectedIndex)

DD5.deleteItem(DD1.selectedIndex)

DD1.deleteItem(DD2.selectedIndex)

DD1.deleteItem(DD3.selectedIndex)

DD1.deleteItem(DD4.selectedIndex)

DD1.deleteItem(DD5.selectedIndex)

Am I on the right track here?  How did you initially set this up?  Did you just open the XML editor and type it in?

Avatar

Former Community Member

Now I understand what you mean by how did I set this up.

I enter the code into the script Editor. This can be activated under the Window menu or you can toggle it on and off by using Ctrl-Shift-F5. It will appear on top of the drawing area. It can be resized to fit your need. There are three DD across the top that are useful for you. Th e1st allows you to pick an event to code against, the 2nd allows you to choose the language that you want to code in (Javascript or FormCalc - most of the time you will use Javascript) and the 3rd one allows you to indicate where to run the code (Client or Server). Unless you have LiveCycle Server always pick client.

Regarding your specific problem, it won't be that simply to keep all of the DDs in sync. I have a different idea where we will populate the DD from the preopen event using an array that represents the list itself. As you select on of th eoptions I eliminate it from the array then populate accordingly.

I am not a programmer so I am struggling with the coding. I will continue to work on it and update this post with a revised sample when I am done.

Paul

Avatar

Level 1

Very cool.  Now that I know where to look and what to look at (somewhat) I'll keep playing around and see if I stumble upon the answer by accident.  Feel free to work with it if you choose to, I won't complain!  Thanks again.

Avatar

Correct answer by
Former Community Member

Here is an updated form. I had to get help from one of my programmer friends so it involves some sophosticated code. I used a script object to keep the volume of code down.

Have a look and let me know what you think.

Paul

Avatar

Level 1

That's awesome!  Exactly what I was looking for although looking at the scripts, I doubt I would figure it out on my own. 

Avatar

Former Community Member

All that we have done is proved that it is possible. Are you going to have many of those type of questions? The way I set it up will only work for 1 question. If you have more questions then we should modify the form to handle that. Are there different questions with different grading options? Then that should be taken into account too.

Paul

Avatar

Level 1

Okay, that first question was hypothetical to see if and how drop down lists worked.  Here is an actual application that I would like to use this in.  I've been going over the script and code presented earlier and I just can't make it work.  I'm attaching a form I made for a weekly NFL thing that some friends and I do.  The object is to pick the winner of the game and then rank your confidence in that team winning (14 being the highest chance of winning, 1 being the lowest).  What I would like to do is be able to fill out the form and assign the number rank with each pick.  If I assign a 10 to the first game, I don't want to be able to assign 10 to any other games.  I have actually gotten this to work but a problem I run into is that if I mistakenly assign a 10 to the first game and then change it to 9, then both 9 AND 10 are not available in the other boxes.  Does that make sense?

Avatar

Former Community Member

Ok i have externalized everything I could into a function (see the MyScript object in the Hierarchy). If you need to adjust the sheet for more or less games you will need to adjust this script. The array at the top holds the valid values that you want to display. Each drop down has been renamed appropriatly. If you have a week with 16 Games you will need to add two lines for the new DD that you will need for the games in the create array function. Simply copy one of the existing lines and adjust it accordingly. Also there is code on th epreOpen event of each DD. It is the same for all DD so any new one you add must have this code also.

Paul

Avatar

Level 1

Okay, that is definitely an improvement.  I'm still seeing the same problem that I was unable to work out earlier though.  To see what I mean, do the following:

In the preview PDF tab of LiveCycle, select "1" for the rank of Game 1.  Select "2" for the rank of Game 2.  Go back and change the rank of Game 1 to "3".  Now, when you go to rank Game 4, "1" "2" and "3" are not available, even though only "2" and "3" have been used.  I guess what I'm saying is that I can't figure out how to repopulate the array after changing an answer.

One other issue that I noticed is that I had added a <none> field to designate an unanswered field.  Once you place a rank into that field, there is no choice to remove that rank (basically to go back to the beginning for that field alone).  I'm not sure if it would even be possible since all of the other rank fields are accessing the same list of possible field entries.  At best, the way I'm understanding it, I would be able to reset only one of the ranking fields to show "<none>" which would then pull that value out of the possible list values available for the other rank fields.

Sorry if this isn't making any sense.

Avatar

Former Community Member

Ok I think I have what you want .....you can now change a value that you have already chosen and I added a reset all DD buttons at the button. If you want to allow a <None> selection then you may be able to achieve this by adding a reset button beside each checkbox and having the code:

xfa.host.resetData("Name of field to reset");

Paul

Avatar

Level 1

This is extremely close to what I meant.  If you play with the drop downs back and forth changing numbers, it gets stuck where it won't show a number it is supposed to.  After a few clicks around in other drop downs, that number will show up again.  Although I really have no clue what it is doing behind the scenes, it seems like the issue is with the flow from top to bottom and it takes a little time to catch up maybe?  Another interesting thing that I noticed is the reset button that you put in.  It definitely resets all the drop down boxes to <none> but all of the values that had been chosen prior to hitting reset (with the exception of the last choice for some reason) are still deleted from the availability list. 

The following has evaluated to null or missing: ==> liqladmin("SELECT id, value FROM metrics WHERE id = 'net_accepted_solutions' and user.id = '${acceptedAnswer.author.id}'").data.items [in template "analytics-container" at line 83, column 41] ---- Tip: It's the step after the last dot that caused this error, not those before it. ---- Tip: If the failing expression is known to be legally refer to something that's sometimes null or missing, either specify a default value like myOptionalVar!myDefault, or use <#if myOptionalVar??>when-present<#else>when-missing. (These only cover the last step of the expression; to cover the whole expression, use parenthesis: (myOptionalVar.foo)!myDefault, (myOptionalVar.foo)?? ---- ---- FTL stack trace ("~" means nesting-related): - Failed at: #assign answerAuthorNetSolutions = li... [in template "analytics-container" at line 83, column 5] ----