cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
gasilva8
Helper II
Helper II

Change visibility of specific items in a gallery based on a toggle

I've created a Form based on a gallery, and now I'm trying to set items visibility based on user's choice. In short, I have a toggle button inside the gallery, and I'm trying to show/hide a TextInput field when the toggle is checked/unchecked.

The problem here is that I can't set a "ThisItem.TextInput.Visible" to the Toggle's OnCheck/OnUncheck (not that if I know of), and if I set a TextInput visibility's variable to update to true/false on the Toggle, that action updates the visibility of all TextInput fields inside the gallery, while I wanna show/hide just the TextInput inside the Item where the Toggle is checked/unchecked.

 

Bellow is what I tried.

For the TextInput:

TextInput.Visible = txtVisibility

For the Toggle OnCheck:

Toggle.OnCheck = Set(txtVisibility,true)

 For the Toggle OnUncheck:

Toggle.UnCheck = Set(txtVisibility,false)

 

I can't find a way to do that work. Any help will be usefull.

Thanks!!

1 ACCEPTED SOLUTION

Accepted Solutions
GarethPrisk
Resident Rockstar
Resident Rockstar

The Toggle.OnCheck and UnCheck are behavior function hooks. You don't reference them in other controls, but instead they allow you to add code for a "behavior" as you alluded to.

 

Instead, you can reference the control's Value property. In the case a of Boolean control (Toggle, Checkbox) it will return as true/false.

 

Set the TextInput.Visible property equal to Toggle.Value

View solution in original post

6 REPLIES 6
Ethan_R
Super User
Super User

Hi @gasilva8 ,

Yes, It is possible to have this, you will have to use a collection where you will store Unique ID of the items within gallery. Then show the visibility of the textbox based on checking if that Unique row ID is in that collection.

 

 

GarethPrisk
Resident Rockstar
Resident Rockstar

The Toggle.OnCheck and UnCheck are behavior function hooks. You don't reference them in other controls, but instead they allow you to add code for a "behavior" as you alluded to.

 

Instead, you can reference the control's Value property. In the case a of Boolean control (Toggle, Checkbox) it will return as true/false.

 

Set the TextInput.Visible property equal to Toggle.Value

GarethPrisk
Resident Rockstar
Resident Rockstar

I missed the Gallery aspect of this, but my suggestion will work in most scenarios.

PowerApps is smart enough to handle row-by-row logic, for individual gallery control's, but can become a bit finicky in complicated situations.

Ethan_R
Super User
Super User

Here's an example,

I have created a sample data where ID is Unique ID.

Toggle and Textbox is added.

 

//OnCheck Property of Toggle

Collect(
    colToggleValues,
    {
        ID: ThisItem.ID
    }
);
//UnCheck property of Toggle

RemoveIf(
    colToggleValues,
    ID = ThisItem.ID
)
// Visible property of Textbox

If(ThisItem.ID in colToggleValues.ID, true, false)

Result,

Ethan_R_0-1634752989198.png

Ethan_R_1-1634753002961.png

 

Hope this helps

Thank you @GarethPrisk !!

I didn't know about the Toggle's property .Value. That worked perfectly.

Thank you @Ethan_R.

I thought about that workaround, but was trying to find a simpler solution.

Helpful resources

Announcements
PA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

This training provides practical hands-on experience in creating Power Apps solutions in a full-day of instructor-led App creation workshop.

Microsoft Build 768x460.png

Microsoft Build is May 24-26. Have you registered yet?

Come together to explore latest innovations in code and application development—and gain insights from experts from around the world.

May UG Leader Call Carousel 768x460.png

What difference can a User Group make for you?

At the monthly call, connect with other leaders and find out how community makes your experience even better.

Top Solution Authors
Top Kudoed Authors
Users online (2,532)