Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
BedrockMission!

Learn more

View all

Sign in to view all badges

SOLVED

Switch statement default setting

joflo723
Level 4
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
radzmar
Correct answer by
Level 10
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
MinusZero
Level 7
Level 7

Hi,

The default case for your switch would be:

default:

//some code for everything else

break;

joflo723
Level 4
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?

radzmar
Correct answer by
Level 10
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

joflo723
Level 4
Level 4

Thank you Radzmar! That did the trick!

Jo