Please add the use of switch case or else if into SC and AC. There is a real need, especially in complex projects.
Bump.
Over 2 years on this one, is this ever going to happen or shall we just accept it is not and sulk
I know how you feel. One of mine Client-side image resizing was requested Oct 2018 and still no sign despite having 45 votes.
Bump.
Bump.
Perhaps a factor in this feature being implemented (or not) is that @George feels it wouldn't be useful or needed.
I don't doubt there is some good advice here, but I don't understand the point about nested conditionals. I expect one of the main reasons that people want else-if statements etc. is to avoid the need to use nested conditions - which are indeed difficult to manage.
It's also been suggested there's less need for this feature because we now have the library feature.
I would suggest there's even more need for switch/else-if functionality, to increase the usefulness of the library feature. A particularly useful library file might be able to take a long list of parameters from different API files; what better way to handle these than with switch or else-if statements. The alternative at the moment would be to use some very clumsy code.
I was looking at a large chunk of code I maintain/develop (in a different environment). It contains over 1300 Else-If statements. I'm pretty confident these help to make the code better and easier to maintain, rather than the opposite. I sometimes consider the possibility of recreating this in Wappler; the thought would be a lot more appealing if this basic programming feature were available.
Anyway, I live in hope...
Got to agree with you on that
Do be able to say
switch( "expression" ) {
case "X":
run library APIaction 1
break;
case "Y" :
run library APIaction2
break;
default:
run library APIaction2
}
is the perfect compliment to library actions. Like you have have some actions into hundreds of lines liked with decoding some pretty big API responses with loads of nested if/ else statements and they make it really difficult to manage
Differences between switch case and if else;
I think it will help many users.
The inclusion of both would be great and make this aspect of Wappler much more powerful.
+1 vote for Switch Case functionality
In the interim, could somebody explain how to do a nested condition? I am trying to create a login_redirect procedure by which depending on the role of the person logging in, I will redirect her to different pages, see example below:
But the nested condition is not working the way I set it.
Thanks in advance for your help.
Hello Jay
For a redirect, there is a special step of the server action, which is called a Redirect
. Here is a simple example of a redirect after authorization:
Thanks! Is there a way to nest redirects? I have 6 user roles to redirect to 6 different pages.
Just remember this if using node...
Sure. If you refer to your screen, then instead of Set Value
, you need to put Redirect
. Iâm also not sure if the condition is correct. Did you write it manually or create it using the Wappler interface? It just seems that the correct condition should be a record like: {{current_user[0].role == 'admin'}}
The current_user
table itself should be filtered based on the user ID, which, judging by your screenshot, you take from Globals
.
If this is the case, then this server action will redirect users according to their role to different pages.
This is not correct for a single query. It does not return an array, so there is no index to reference.
However, this option works correctly. I just checked in my server action and removed the index reference and the condition stopped working.
Right, your screenshot is using a query for multiple records but Jay is using the single query option.
Now I get it what youâre talking about. Yes, thatâs right. I didnât notice that Jay was using a different type of database query.