Dynamic visibility of Gallery Items based on previous item data in Canvas PowerApps
Introduction
Let’s say you come across a scenario where you want to show dynamic records for your gallery items based on previous record details.
For example: Let’s say a basic Q&A where the User should input data and then proceed.
So, I have created something similar that will help in developing such a design quickly and efficiently.
Steps to implement in Canvas PowerApps
Step 1: Create a collection that will store data of the gallery. (You can use Dataverse records here with the unique identifier in the collection.)
Note: Collection is better to use if you are referring to the same table. If you use Gallery.AllItems then you will encounter errors and circular reference issues.
//A Button to execute a collection of records. (You can trigger onLoad of screen as well)
ClearCollect(
colAnswers,
{
ID: 1,
Question: "This is 1st Question (always visible)",
isVisible: true
},
{
ID: 2,
Question: "This is 2nd Question",
isVisible: false
},
{
ID: 3,
Question: "This is 3rd Question",
isVisible: false
},
{
ID: 4,
Question: "This is 4th Question",
isVisible: false
}
)
Set a Blank Vertical Gallery where Items property is as follows:
//Items property on Gallery
Filter(colAnswers,isVisible = true)
Step 2: Add a Text Input in Gallery that will accept the User’s Input Along with Questions.
//OnChange of Text-Input
If(
IsBlank(TxtAnswer.Text),
UpdateIf(
colAnswers,
ID > ThisItem.ID,
{
isVisible: !IsBlank(TxtAnswer.Text)
}
),
UpdateIf(
colAnswers,
ID = ThisItem.ID + 1,
{
isVisible: !IsBlank(TxtAnswer.Text)
}
)
)
Conclusion
That’s all. You got dynamic content based on previous values.
I hope this helps!