Expand my Community achievements bar.

Guidelines for the Responsible Use of Generative AI in the Experience Cloud Community.
SOLVED

Making visible or invisible drop-down lists depending on the value of another drop-down list. Help!

Avatar

Level 1

Hello,

I need to create the next form... I want to select at the beginning of the form between 3 options (imagine: "Opt1", "Opt2", and "Opt3"). And after that, I want to make visible 10 different drop-down lists. I mean, if I choose "Opt1", the 10 drop-down lists related to "Opt1" will become visible (the whole drop-down list, including the text of the title and the own drop-down list). Otherwise, if I choose "Opt2", the 10 drop-down lists related to "Opt2" will become visible, and the same to "Opt3".

This problem, that seems to be very easy to be solved, is impossible for me. I've read hundreds of forums, and manuals, but I cannot find the solution. I've tried with thousands of events, but I cannot make the form work as I want... So, please, can somebody help me?

Thank you very much.

1 Accepted Solution

Avatar

Correct answer by
Level 10

Hi,

HEre is an example. The script is in the change event of the dropdown. The easiest way is to group your dropdowns into subforms, then you just have to script for the visibility of three subforms, instead of 30 dropdowns.

The script looks at the user's choice and changes the visibility using a switch statement. An if statement in the exit event would work as well.

switch (xfa.event.newText)

{

     case 'Option 1':

          option1.presence = "visible";

          option2.presence = "hidden";

          option3.presence = "hidden";

          break;

          

     case 'Option 2':

          option1.presence = "hidden";

          option2.presence = "visible";

          option3.presence = "hidden";

          break;

          

     case 'Option 3':

          option1.presence = "hidden";

          option2.presence = "hidden";

          option3.presence = "visible";

          break;

          

     default:

          option1.presence = "hidden";

          option2.presence = "hidden";

          option3.presence = "hidden";

          break;

}

Note that all of the three subforms are hidden in the design view. The dropdown choice makes the appropriate subform visible.

In the design view you can select a subform in the hierarchy view and in the Object/Field tab change its visibility to visible, if you want to work on it in design.

Hope that helps,

Niall

View solution in original post

11 Replies

Avatar

Correct answer by
Level 10

Hi,

HEre is an example. The script is in the change event of the dropdown. The easiest way is to group your dropdowns into subforms, then you just have to script for the visibility of three subforms, instead of 30 dropdowns.

The script looks at the user's choice and changes the visibility using a switch statement. An if statement in the exit event would work as well.

switch (xfa.event.newText)

{

     case 'Option 1':

          option1.presence = "visible";

          option2.presence = "hidden";

          option3.presence = "hidden";

          break;

          

     case 'Option 2':

          option1.presence = "hidden";

          option2.presence = "visible";

          option3.presence = "hidden";

          break;

          

     case 'Option 3':

          option1.presence = "hidden";

          option2.presence = "hidden";

          option3.presence = "visible";

          break;

          

     default:

          option1.presence = "hidden";

          option2.presence = "hidden";

          option3.presence = "hidden";

          break;

}

Note that all of the three subforms are hidden in the design view. The dropdown choice makes the appropriate subform visible.

In the design view you can select a subform in the hierarchy view and in the Object/Field tab change its visibility to visible, if you want to work on it in design.

Hope that helps,

Niall

Avatar

Level 7

Hi Niall,

I'm seeing the switch statement pop up more and more in the forums, is there a script repository anywhere that users can be referred to rather than posting and re-posting it? I've found it to be very useful since I first encountered it, I'm curious to know if it (and other common script snippets) are catalogued somewhere.

Thanks,

djaknow

Avatar

Level 10

Hi djaknow,

I have been thinking of a project for a while now. The plan is to have a one page form with a dropdown for all script events. The form would then change to show the good aspects of that script event and things to watch out for. Also it would have examples of a script for that event. Some events can have an adverse affect on performance (being called unnecessarily).  I was thinking of a "performance" scale from 1 to 5...

What put me in mind of it was a post by John Brinkman (along with a useful script reference form). See http://blogs.adobe.com/formfeed/2009/09/xfa_scripting_api_reference.html. This is useful for syntax, but lacks examples for novices/non-programmers (imho).

The script example textfield would be scrollable.

So far all I have is an outline. Here it is... haha - very blank canvas...

As I would be doing this around the day job, any help would be appreciated. It will also take a bit of time to develop. I would hope that Paul G. would review when drafted.

Any views...

Niall

Avatar

Former Community Member

I woudl be happy to review it ....also the sequence of events firing is also important. There was a test form created some time ago that demonstrated the events in the order that they were fired. It was posted on DevNet but I coul dnot find it when I looked. I have a copy of it if you want it for reference.

Paul

Avatar

Level 10

Thanks Paul,

I found it...

It seems to indicate that calculate, validate, ready:layout events fire automatically after events like mouseEnter and mouseExit. Is this correct?

I will post a new thread when I start to get a shape on the form.

Thanks,

Niall

Avatar

Former Community Member

Yes that is correct ....

I suggest that you send me a private message when you are ready for review. That way we will not get early non ready versions on the form. I can also get a couple of extra people around here to review as well.

paul

Avatar

Level 7

I'm happy to help with reviewing it as well, please let me know if I can do anything.

Avatar

Level 1

Thanks a lot. Now it works perfect.

Kind regards.

Avatar

Level 10

I've been thinking of doing a website or something but the problem I haven't got around yet is how to catalogue stuff in a reasonable manner. I see the same questions popping up repeatedly in all the forums - it would be nice if there were One Forum to Rule Them All. I follow this forum, the Acrobat User Community and the Adobe LiveCycle Developers on Google Groups as well as several blogs. I quite often see people posting the same question on all forums at the same time.There is Thom Parker's www.pdfscripting.com but I think a free source would be better...I haven't got work to spring for a subscription there yet so can't really speak to how good it is.

Maybe a FAQ? Or FAQ in ineractive PDF form?

Avatar

Level 10

Hi Jono,

One of the online MAX sessions highlighted that in LiveCycle Cafe you can make "notes" of forum posts and script examples. This makes it easier to find in the Notes panel.

Also might be worth sending a post to http://blogs.adobe.com/livecycledocs/, as they appear to be thinking along the same lines.

Good luck,

Niall

Avatar

Level 10

I've been using Evernote for storing info, but I haven't been using it that much of late...As I put more stuff in it gets harder to find things so I end up relying on memory and google instead.