Element Visibility based on current user variable

Hi All,

This might be quite basic, but I want to add a button, which is visible only when the current user is an ADMIN. In order to determine if a user is admin, I added a “yes/no” field to the default “user” data type.
In order to implement that, I added a workflow on the relevant menu of “page loaded” with the action of hide the button element when the current user is not admin.
The problem is the delay. If the user is not admin then while the page loading the button appears and disappears after the page finished to load.

I guess that there is a much better why to implement this functionality. Would love to get your insights.
Best regards,

Hi @eviatar!

There are two things you can pick up from this that are both valuable in learning Bubble:

Rather than using an action to show or hide elements, you can use Conditions. Conditions is kind of an ongoing if-this-then-that query that allows for an element to change one or more properties if certain conditions are met. In this case, the condition would be Current Users’s Admin is “Yes”.

Reverse visibility
Okay, I just made this term up. But it’s a good rule of thumb to reverse the visibility condition. What I mean is that instead of hiding something based on certain conditions, you should set it as hidden by default, and instead show it when the conditions are met. In your case, the button would be hidden by default, but visible when the Users’s Admin is Yes, instead of the other way around. This way, loading time, connection errors etc. will not show the element when you don’t want it to.

Perfect! Thanks!!!
Much appreciated :slight_smile:

1 Like

This topic was automatically closed after 70 days. New replies are no longer allowed.