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

Switch statement default setting

Avatar

Level 4

I have a dropdown with a switch statement in the exit event with about 80 "cases". There are only 3 of them though that if they are selected, the presence of a text field needs to change to "hidden". Without having to put a "presence" statement on every single case, is there a more efficient way to change the presence of the text field if one of the 3 are selected, and then defaulting back to a "visible" presence if anything else is selected?

Thanks!

1 Accepted Solution

Avatar

Correct answer by
Level 10

You can use a single line of code outside of you switch statement in the dropdown fields change event.

Assuming you want to hide the field when you either select Value12, Value 32 or Value55, the script looks this way:

portal.presence = xfa.event.change.match(/(Value12|Value32|Value55)/gi) ? "hidden" : "visible";

View solution in original post

4 Replies

Avatar

Level 7

Hi,

The default case for your switch would be:

default:

//some code for everything else

break;

Avatar

Level 4

I've tried that, but it isn't working.

My code is:

switch (this.rawValue)

{

//all the cases

default:

    portal.presence = "visible";

    break;

}

The "portal" text field is visible by default, but when you select one of the few options that has it set to hidden, it does disappear, but if you then go back and select any other option that does NOT have its presence specified, it doesn't become visible again. Am I missing anything?

Avatar

Correct answer by
Level 10

You can use a single line of code outside of you switch statement in the dropdown fields change event.

Assuming you want to hide the field when you either select Value12, Value 32 or Value55, the script looks this way:

portal.presence = xfa.event.change.match(/(Value12|Value32|Value55)/gi) ? "hidden" : "visible";

Avatar

Level 4

Thank you Radzmar! That did the trick!

Jo