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

Makeing subforms visible depending on what is selected from the dropdown

Avatar

Level 5

Good day all;

Looks like I am batting “0” today. For some reason I am not able to get a number of things to work today… Maybe I should just write this day off as a loss..;>))

Any way; I am trying, without success to get sub forms to become visible depending on what is selected from a dropdown. I have tried using “switch” (see below) but I end up getting the famous “Syntax” error.

I have also tried an “if” (see below) statement, but that did not seem to work either.

What I would like to have happen is when a user selects 1 of 2 choices 1 of 2 sub forms becomes visible.

As well, if the user has initially selected the wrong dropdown and they select now select the correct one, I would like the incorrect sub form to become invisible again.

I would appreciate any help

switch (this.rawValue)

{

    case "2":

    staffing_inter.presence = "visible";

else

staffing_inter.presence = "hidden";

    break;

}

IF statement

if(this.rawValue = 2 )

{

    staffing_inter.presence = "visible"

}

else{

staffing_inter.presence = "hidden";

}

1 Accepted Solution

Avatar

Correct answer by
Level 10

Couple of things...

Switch() statements don't use "else". You have to specify each value. But you can nest other code inside a switch() statement.

Using a dropdown you have to get the new value when the selection is made.

So (this assumes you've done "Specify Item Values" on the Binding tab for the DDL):

var newValue = this.boundItem(xfa.event.newText);

switch(newValue){

     case "1":

          //code

     break;

     case "2":

          //code

     break;

     //etc.

}

Or with your if statement:

var newValue = this.boundItem(xfa.event.newText);

if(newValue = 2){

    staffing_inter.presence = "visible"

}

else{

     staffing_inter.presence = "hidden";

}

View solution in original post

6 Replies

Avatar

Correct answer by
Level 10

Couple of things...

Switch() statements don't use "else". You have to specify each value. But you can nest other code inside a switch() statement.

Using a dropdown you have to get the new value when the selection is made.

So (this assumes you've done "Specify Item Values" on the Binding tab for the DDL):

var newValue = this.boundItem(xfa.event.newText);

switch(newValue){

     case "1":

          //code

     break;

     case "2":

          //code

     break;

     //etc.

}

Or with your if statement:

var newValue = this.boundItem(xfa.event.newText);

if(newValue = 2){

    staffing_inter.presence = "visible"

}

else{

     staffing_inter.presence = "hidden";

}

Avatar

Level 10

Also, the double equal sign in the test for the if statement...

Avatar

Level 10

Oops missed that! Thanks Niall!

Avatar

Level 5

Thank you Jono and Niall;

I was looking through the forum and found a post by Niall that appears to be working; I was wondering if this should be used or the one that Jono has posted...

staffing_inter.presence = "hidden";

staffing_inter.preAsence = "hidden";

// Then show the appropriate one

if (this.rawValue == "2") {

staffing_inter.presence = "visible";

}

else if (this.rawValue == "3") {

    staffing_exter.presence = "visible";

}

Avatar

Level 10

Whatever works for your needs - that's going to partially depend on your layout and what is visible/not visible at the start.

Avatar

Level 5

Thanks Jono;

It seems that this request is still evolving.. Go figure.. ;>))

Thanks again

Chomp