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!!
Solved! Go to Solution.
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
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.
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
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.
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,
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.
This training provides practical hands-on experience in creating Power Apps solutions in a full-day of instructor-led App creation workshop.
Come together to explore latest innovations in code and application development—and gain insights from experts from around the world.
User | Count |
---|---|
203 | |
71 | |
51 | |
49 | |
20 |
User | Count |
---|---|
263 | |
123 | |
85 | |
79 | |
70 |