Show Hide Power Apps Form Based On Gallery Selected Item

I developed a leave request app in Power Apps. Managers/Approvers can see all the requests and approve/reject waiting for them. When they tap a request, they see all the details. After they approve or reject it, the details form closes automatically.

In this tutorial, I will explain how to show hide Power Apps form based on gallery selected item with a simple scenario.

Show Hide Power Apps Form Based On Gallery Selected Item

In the example below, you can see that on the welcome screen, I clicked on the Team Lead button, which navigated me to the dashboard screen. As a team lead, I can see the employee leave requests that are assigned to me.

When I click on an item in a gallery, a Power Apps form appears on the screen, showing the details of the selected leave request for the gallery. I can approve or reject it here; when I click on the cancel icon, the form disappears.

powerapps edit form selected item

Here is the SharePoint list that stores the employee leave request details.

how to display a power apps form control on gallery selected item

Follow the steps below to achieve this!

1. In the Power Apps application, add the SharePoint list, then create two screens for :

  • Welcome Screen
  • Dashboard Screen

Add a button control for the approver on the welcome screen and provide the code below for its OnSelect property.

ClearCollect(colLeaveRequestDetails,'Employee Leave Requests');Navigate(DashboardScreen);Set(varShowForm,false)

I created a collection [colLeaveRequestDetails] that stores the SharePoint list details to avoid deligations while performing filtrations.

Navigate() function will take us to the provided screen.

show hide power apps form when select an item in gallery

2. On the dashboard screen, add a gallery control and provide the formula below for its Items property.

Also, provide the below code on the OnSelect property of gallery control.

Items = Filter(colLeaveRequestDetails,'Team Lead'.Email =User().Email && TeamLeadApproval.Value ="In Progress")
OnSelect = Set(varShowForm,true)
PowerApps Gallery selected item to form

3.  Now, add a Container and a Form control within that. Then, do the following steps one by one.

Container Fill Property = ColorValue("#ffffff")

Provide the SharePoint list name on the DataSource property of the form control and the formula below on its Item property.

DataSource = 'Employee Leave Requests'
Item = Gal_TeamLead.Selected
DisplayMode = FormMode.View
power apps flyout form

Add two button controls for approve and reject and a cancel badge icon at the top of the form within the container. Provide the following formulas for the OnSelect property of these controls.

Approve button OnSelect property:

Patch(
    'Employee Leave Requests',
    LookUp(
         'Employee Leave Requests',
        ID =Gal_TeamLead.Selected.ID
    ),
    {
        'Team Lead Approval':{Value:"Approved"}
    }
);
Refresh('Employee Leave Requests');
Collect(colLeaveRequestDetails,'Employee Leave Requests')

Using the Patch() function, I’m updating the ‘Team Lead Approval’ status to “Approved.”

  • LookUp() = Used to update the status for gallery-selected items based on condition.
  • ‘Employee Leave Requests’ = Sharepoint list name.

Reject Button OnSelect property:

Patch(
    'Employee Leave Requests',
    LookUp(
         'Employee Leave Requests',
        ID =Gal_TeamLead.Selected.ID
    ),
    {
        'Team Lead Approval':{Value:"Rejected"}
    }
);
Refresh('Employee Leave Requests');
Collect(colLeaveRequestDetails,'Employee Leave Requests')

Here, the status is updated as “Rejected.”

Cancel icon OnSelect property:

Set(varShowForm,false)

Here, we assign the varShowForm to false so the container will be hidden.

power apps flyout form on gallery selection

4. Add the below formula to the Visible property of the Container.

varShowForm

If the varShowForm value is truethe container will be displayed. Otherwise, it will hide.

powerapps edit form from gallery selection

Save the changes and preview the app once. Now, test the application; when you click on any item in the gallery, the selected item details will appear on the form control. When you click on the Cancel icon, the form will be hidden.

I hope you understand how to show and hide Power Apps from control when you click on gallery items. In this article, I also explained how to filter the gallery items based on the current user and status field at a time. Also, approve or reject a leave request from the app itself.

Follow this article if you are also trying to create a Dashboard for approvers in Power Apps, where you can see full details of a leave request before approving or rejecting it.

Also, you may like:

Power Apps functions free pdf

30 Power Apps Functions

This free guide walks you through the 30 most-used Power Apps functions with real business examples, exact syntax, and results you can see.

Download User registration canvas app

DOWNLOAD USER REGISTRATION POWER APPS CANVAS APP

Download a fully functional Power Apps Canvas App (with Power Automate): User Registration App