We need an If-Else Widget (such as a container with 2 sides) - Mendix Forum

We need an If-Else Widget (such as a container with 2 sides)

3

There are 2 things that I think Mendix can improve on:

  1. There could be an IF-ELSE WIDGET that shows something if true or shows something else if otherwise. If else statements come in handy in a lot of situations.
    Doing 
    if (A)
        show A-content;
    if (B)
        show B-content;
    if (C) 
        show C-content;

    Is much less optimal than doing

    if (A)
        show A-content;
    else if (B)
        show B-content;
        else
             show C-content;
    


    This cannot be done in Mendix’s front end. You’ll always have to compute every visibility statement, even if they could be nested.

    We need a way to nest what is shown in a screen/snippet.

  2. The second thing is that you cannot directly have a visibility condition if the user does NOT have a role.
    If you only want to show some content if the user isn’t an Admin, you cannot do it in a low-code manner.
    To do that you’ll have to have a microflow, fetch the current user roles and check if admin is not one of them and then return false (Or some similar approach)
    Let me know if this is not the case. 

asked
3 answers
  1. If you really feel the need for such a widget I think this could be built as a pluggable widget, so just have a try.
  1. I agree that the role based conditional visibility could really be improved (or maybe combined with the standard visibility) to allow for complex expressions.

regards, Fabian

Created

Sorry, my ideas weren’t very organized. Let me rephrase:

There are 2 things that I think Mendix can improve on:

  1. There could be an IF-ELSE WIDGET that shows something if true or shows something else if otherwise. If else statements come in handy in a lot of situations.
    Doing 
    if (A)
        show A-content;
    if (B)
        show B-content;
    if (C) 
        show C-content;

    Is much less optimal than doing

    if (A)
        show A-content;
    else if (B)
        show B-content;
        else
             show C-content;
    


    This cannot be done in Mendix’s front end. You’ll always have to compute every visibility statement, even if they could be nested.

  2. The second thing is that you cannot directly have a visibility condition if the user does NOT have a role.
    If you only want to show some content if the user isn’t an Admin, you cannot do it in a low-code manner.
    To do that you’ll have to have a microflow, fetch the current user roles and check if admin is not one of them and then return false (Or some similar approach)
    Let me know if this is not the case. 

 

You’re totally right. My ideas were not very organized when I wrote this. I’ll edit this post now.

 

Best regards,

João

Created

Visibility is a binary thing. Something is visible or not and a condition is true or not. There is no in between. You can add a condition and if it is true, visibility is turned on. Otherwise it is turned off.
How would a “if-then-else” statement change something?

Created