Switch statement default setting

Avatar

Avatar

joflo723

Avatar

joflo723

joflo723

09-11-2018

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!

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar

radzmar

MVP

Total Posts

2.6K

Likes

386

Correct Answer

485

Avatar

radzmar

MVP

Total Posts

2.6K

Likes

386

Correct Answer

485
radzmar
MVP

12-11-2018

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";

Answers (3)

Answers (3)

Avatar

Avatar

joflo723

Avatar

joflo723

joflo723

12-11-2018

Thank you Radzmar! That did the trick!

Jo

Avatar

Avatar

joflo723

Avatar

joflo723

joflo723

12-11-2018

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

Avatar

MinusZero

Avatar

MinusZero

MinusZero

11-11-2018

Hi,

The default case for your switch would be:

default:

//some code for everything else

break;