Skip to main content

Notifications

Power Apps - Building Power Apps
Answered

Gallery Tabs - Show or Hide Tabs based on Field Value

Posted on 29 Oct 2024 15:10:04 by 855
I have a list of Tabs using a Gallery and I would like to hide some of those tabs if a field value equals as certain value.  I want to hide the Subcontracting tabs based on a field in the form.  
 
Items = 
Table(
    {
        ID: 1,
        Label: "General Info"
    },
    {
        ID: 2,
        Label: "Contract Info"
    },
    {
        ID: 3,
        Label: "Prime Info"
    },
    {
        ID: 4,
        Label: "Gov't Info"
    },
    {
        ID: 5,
        Label: "T&C/Clause Info"
    },
    {
        ID: 6,
        Label: "Deliverable Info"
    },
    {
        ID: 7,
        Label: "Employee Info"
    },
    {
        ID: 8,
        Label: "Security Info"
    },
    {
        ID: 9,
        Label: "Billing/Invoices Info"
    },
    {
        ID: 10,
        Label: "Subcontracting Info"
    },
    {
        ID: 11,
        Label: "Subcontracting Details"
    },
    {
        ID: 12,
        Label: "Notes/Attachments"
    },
    {
        ID: 13,
        Label: "Signatures"
    }
)
Categories:
  • Suggested answer
    KeithAtherton Profile Picture
    KeithAtherton 3,565 on 30 Oct 2024 at 13:07:13
    Gallery Tabs - Show or Hide Tabs based on Field Value
    That code looks good. Did you also set the gallery item control (I'm guessing button) Visible property to ThisItem.Visible?
  • kmw1130 Profile Picture
    kmw1130 855 on 30 Oct 2024 at 11:42:45
    Gallery Tabs - Show or Hide Tabs based on Field Value
    @KeithAtherton,
    I added your suggestion on the Items:
    But it didn't seem to change when Sub wasn't selected.
     
    Did I not add it correctly?
  • RyanAutomates Profile Picture
    RyanAutomates 70 on 29 Oct 2024 at 16:18:42
    Gallery Tabs - Show or Hide Tabs based on Field Value
    Hello,
     
    I haven't used a table inside a gallery before, but it sounds like you're almost trying to make a sort of dynamic menu? I think there might be a few approaches to what you would like to do:
     
    1) In the visible property of each control in your row, you can put an If condition for each row, or use a switch statement:
     
         If(ThisItem.ID = 3 && !examplebooleanfieldonyourform, false, true),
         If(ThisItem.ID = 4 && !anotherexamplebooleanfieldonyourform, false, true)
         
         Switch(
              True,
              Condition1, Result1,
              Condition2, Result2,
              Condition3, Result3,
              DefaultResult
    )
     
    This might not produce the UI requirements you are looking for however, as it may leave you with a row of empty space.
     
     
    2) The answer that's probably best is to dynamically filter out any row in your table by using a "Filter" operator with conditions on the end:
     
         Filter(
              Table(
                        { ID: 1, Label: "General Info" },
                        { ID: 2, Label: "Contract Info" },
                        { ID: 3, Label: "Prime Info" },
                        { ID: 4, Label: "Gov't Info" },
                        { ID: 5, Label: "T&C/Clause Info" },
                        { ID: 6, Label: "Deliverable Info" },
                        { ID: 7, Label: "Employee Info" },
                        { ID: 8, Label: "Security Info" },
                        { ID: 9, Label: "Billing/Invoices Info" },
                        { ID: 10, Label: "Subcontracting Info" },
                        { ID: 11, Label: "Subcontracting Details" },
                        { ID: 12, Label: "Notes/Attachments" },
                        { ID: 13, Label: "Signatures" }
              ),
              !(ID = 3 && !examplebooleanfieldonyourform) // Condition to exclude "Prime Info" row if examplebooleanfieldonyourform is false
    )
     
    I haven't tried this myself with a table, but I think it might make the options you don't want displayed to disappear.
     
     
    3) You could put containers inside the gallery for each row to dynamically toggle visibility of each container based on conditions. This would give you more granular control over every aspect but would require writing or copy pasting lots more Power Fx.
     
     
    Hope this helps! :)
  • Verified answer
    KeithAtherton Profile Picture
    KeithAtherton 3,565 on 29 Oct 2024 at 15:49:26
    Gallery Tabs - Show or Hide Tabs based on Field Value
    Hey. This approach looks good - you could add another field called "Visible" which checks the condition of interest (in my case, txtMyField.Text = "TEST") then use that field value for the gallery item button visible property:
    Table(
        {
            ID: 1,
            Label: "General Info",
            Visible:txtMyField.Text = "TEST"
        },
    // etc
     

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

October 2024 Newsletter…

October 2024 Community Newsletter…

Community Update Oct 28…

Power Platform Community Update…

Tuesday Tip #4 How to Conntact Support…

Welcome to a brand new series, Tuesday Tips…

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 143,081

#2
RandyHayes Profile Picture

RandyHayes 76,308

#3
Pstork1 Profile Picture

Pstork1 63,795

Leaderboard