If Else conditions for calculations

I need to go to a certain page based on a value selected in a drop down value list. Each value in this dropdown list will take the user to a different page once they select the “Next” button at the bottom at the page.

In Javascript programming, I could do something similar as

if ( value = “value1” ) {
return path 1 value
}
else if ( value = “value2” ) {
return path 2 value
}
etc.

Is there a way to do this in the page builder using a calc type of JSON attribute. Please let me know. Thanks!

Sure is, if you have the model in the object that the dropdown selects you can simply do something like thisL

// object selected in model.theChoice
{
  "theLabel" : "Page #1",
  "path" : "/p1"
}

and the named action that that would call would be:

[{
 "action" : "path",
 "function" : "action.options.path == " model.theChoice.path ",
 "options" : {
       "path" : "this will be replaced byt the function above"
  } 
 }]

This is off top of head so may be typos

1 Like

Thanks Charles!

I got it to work using this:

{
        "action": "path",
        "function": "action.options.path = model[model.request].path",
        "options": {
            "path": "action.options.path"
        }
    }

where model.request is my choice.