15
Views
5
Comments
Solved
How to set a button from menu invisible depending on User role?
Application Type
Traditional Web

Hey! I am build an app for my mom and she is a teacher. Basically I have a data base with the sutdentes name and their grades. So, the students and my mom do a login and my gets the role "admin" and the students "students". So, if the it is one student, i want the menu to only show 1 button and if it is my mom i want to show 2. How do I do that? Please help :)

Rank: #87
Solution

Hello there Gonçalo,

You can use Check<Role>Role function:


In the menu, you may place some If widgets around the buttons and show them accordingly, using these functions. Or use this function in Visible property of the buttons.

In order to use these functions, you just need to pass an UserId as input parameter. Since you want to check for the logged user, you just need to use something like this:

CheckAdminRole(GetUserId())


Hope that this helps you!


Kind regards,

Rui Barradas

Rank: #13474

But how do I set the button Invisible?

Rank: #87

Hello Gonçalo,

Like I said, you can use an If widget to enclose your buttons:

In this example, AdminButton will only be appear if the current logged User has the Admin Role.


Kind regards,

Rui Barradas

Rank: #944

Hi,


Following Rui's logic, I think You could place the button inside an if, which will be based on a boolean variable. This boolean variable should be set to true inside a server action that checks the required role. This action could be initialized on a specific event of the screen, following best practices.


Kind regards,

Ivan Leitão

Rank: #87

Hello Ivo,

Your response is for Reactive Web Apps, it doesn't apply for Traditional Web Apps (which is the case).

In a Traditional Web App, there are no screen events neither client actions.


Kind regards,

Rui Barradas