cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
HMP
Helper I
Helper I

Override visibility with a button

I have a Powerapps form connected to a SharePoint list that includes a single Choice column called Status. When someone attempts to change the status to "Confirmed to Discard" or "Discarded", I want a pop-up to become visible, asking them to confirm if they can discard the samples. I have created a pop-up of sorts within the Status datacard by grouping a rectangle with a label and two buttons. I have set the Group1.Visible to If("Discard" in DataCardValue51.Selected.Value,true). This works as expected.

 

What I would like to have happen is...

- If the person clicks the NO button, I want the pop-up to close and put the Status choice to what it was before they tried one of the options with "Discard".

- If they click the YES button, I want the pop-up to close and accept their change.

 

So the button needs to conditionally override the visibility when YES is selected, otherwise the pop-up remains visible because "Discard" is in the selected value. I think I need to set some sort of variable for the visibility, but I'm new to PowerApps and don't know how to do this. Any advice would be appreciated!

2 ACCEPTED SOLUTIONS

Accepted Solutions
Roverandom
Solution Supplier
Solution Supplier

Well, basically there are a few things to do, for example, what type of variable is best to use for your case, global or context variable.
Anyway, in my example I use global variable, if it doesn't work for your case, let me know.

Therefore, in the OnStart property of the App I defined the following variables:

 

/*
The gblReset variable is for resetting the option control to its original state, ie, no choice. Strangely, variables that are used to reset a control, Power Apps doesn't seem to take it well, that's why I set the variable first to false and then to true, as the initial state of the control is unselected.
*/
Set(gblReset, false);
Set(gblReset, true);

// The gblShowPopUp variable is for defining whether the popup is visible or not.
Set(gblShowPopUp, false);

 

In the Reset property of the selection control, place the gblReset variable:

Roverandom_0-1660614423296.png

 

In the OnSelect property of the selection control, set the gblShowPopUp variable to true:

Roverandom_6-1660614903342.png

 

 

From there, in your popup, set the Visible property to the gblShowPopUp variable:

Roverandom_3-1660614607566.png

 

In the OnSelect property of the NO button, set:

Roverandom_4-1660614654462.png

Notice that we defined the variables again...

 

On the Yes button, in the OnSelect property, proceed with what your App should do...

Roverandom_5-1660614731156.png

 

Final result:

showpopup.gif



Hi! I hope I was helpfull. Please always mark the answer that helped you, so others who need it will find it faster.



Roverandom is a book by J.R.R Tolkien. I'm a big fan of his works and as Frodo, Aragorn or Gollum are already widely used, I decided to use this nickname.

View solution in original post

Roverandom
Solution Supplier
Solution Supplier


This is on me, as I may not have been clear in my initial post; I'd like the pop-up to appear only if the selected option is "Discarded" or "Confirmed to Discard" (i.e. contains "Discard"). There are many other choices, such as "Processing" and "Analyzing", where I don't need a confirmation pop-up.

 

Well, in this case you can use a Switch function (in the option's OnSelect property) to test if the selected value contains a word necessary for the popup to appear, or even use the IF function with OR. It would be more or less like this:

 

Choice.OnSelect:

// using switch function
Switch(
    Self.Selected.Value,
    "Selected Value 1",
    Set(gblShowPopUp, true),
    "Selected Value 2", "does nothing",
    // and so on
)

// using IF with OR function
If(
    Or(
        Self.Selected.Value = "Selected value 1",
        Self.Selected.Value = "Selected value 3"
    ),
    Set(gblShowPopUp, true),
    "does nothing"
)

 


As for the last step, where you indicate I should proceed with code telling my App what it should do, all I need it do when "Yes" is selected, is to accept the change, which it appears to do. Does this mean no additional code is needed for the Yes button's OnSelect property?


Correct, no additional code is needed in this case.



Hi! I hope I was helpfull. Please always mark the answer that helped you, so others who need it will find it faster.



Roverandom is a book by J.R.R Tolkien. I'm a big fan of his works and as Frodo, Aragorn or Gollum are already widely used, I decided to use this nickname.

View solution in original post

4 REPLIES 4
Roverandom
Solution Supplier
Solution Supplier

Well, basically there are a few things to do, for example, what type of variable is best to use for your case, global or context variable.
Anyway, in my example I use global variable, if it doesn't work for your case, let me know.

Therefore, in the OnStart property of the App I defined the following variables:

 

/*
The gblReset variable is for resetting the option control to its original state, ie, no choice. Strangely, variables that are used to reset a control, Power Apps doesn't seem to take it well, that's why I set the variable first to false and then to true, as the initial state of the control is unselected.
*/
Set(gblReset, false);
Set(gblReset, true);

// The gblShowPopUp variable is for defining whether the popup is visible or not.
Set(gblShowPopUp, false);

 

In the Reset property of the selection control, place the gblReset variable:

Roverandom_0-1660614423296.png

 

In the OnSelect property of the selection control, set the gblShowPopUp variable to true:

Roverandom_6-1660614903342.png

 

 

From there, in your popup, set the Visible property to the gblShowPopUp variable:

Roverandom_3-1660614607566.png

 

In the OnSelect property of the NO button, set:

Roverandom_4-1660614654462.png

Notice that we defined the variables again...

 

On the Yes button, in the OnSelect property, proceed with what your App should do...

Roverandom_5-1660614731156.png

 

Final result:

showpopup.gif



Hi! I hope I was helpfull. Please always mark the answer that helped you, so others who need it will find it faster.



Roverandom is a book by J.R.R Tolkien. I'm a big fan of his works and as Frodo, Aragorn or Gollum are already widely used, I decided to use this nickname.

Your instructions are excellent, and I was able to replicate what you did. Thank you!

 

This is on me, as I may not have been clear in my initial post; I'd like the pop-up to appear only if the selected option is "Discarded" or "Confirmed to Discard" (i.e. contains "Discard"). There are many other choices, such as "Processing" and "Analyzing", where I don't need a confirmation pop-up.

 

As for the last step, where you indicate I should proceed with code telling my App what it should do, all I need it do when "Yes" is selected, is to accept the change, which it appears to do. Does this mean no additional code is needed for the Yes button's OnSelect property?

Roverandom
Solution Supplier
Solution Supplier


This is on me, as I may not have been clear in my initial post; I'd like the pop-up to appear only if the selected option is "Discarded" or "Confirmed to Discard" (i.e. contains "Discard"). There are many other choices, such as "Processing" and "Analyzing", where I don't need a confirmation pop-up.

 

Well, in this case you can use a Switch function (in the option's OnSelect property) to test if the selected value contains a word necessary for the popup to appear, or even use the IF function with OR. It would be more or less like this:

 

Choice.OnSelect:

// using switch function
Switch(
    Self.Selected.Value,
    "Selected Value 1",
    Set(gblShowPopUp, true),
    "Selected Value 2", "does nothing",
    // and so on
)

// using IF with OR function
If(
    Or(
        Self.Selected.Value = "Selected value 1",
        Self.Selected.Value = "Selected value 3"
    ),
    Set(gblShowPopUp, true),
    "does nothing"
)

 


As for the last step, where you indicate I should proceed with code telling my App what it should do, all I need it do when "Yes" is selected, is to accept the change, which it appears to do. Does this mean no additional code is needed for the Yes button's OnSelect property?


Correct, no additional code is needed in this case.



Hi! I hope I was helpfull. Please always mark the answer that helped you, so others who need it will find it faster.



Roverandom is a book by J.R.R Tolkien. I'm a big fan of his works and as Frodo, Aragorn or Gollum are already widely used, I decided to use this nickname.

This works exactly as needed. Thank you so much! 

Helpful resources

Announcements
Power Apps News & Annoucements carousel

Power Apps News & Announcements

Keep up to date with current events and community announcements in the Power Apps community.

Community Call Conversations

Introducing the Community Calls Conversations

A great place where you can stay up to date with community calls and interact with the speakers.

Power Apps Community Blog Carousel

Power Apps Community Blog

Check out the latest Community Blog from the community!

Top Solution Authors
Top Kudoed Authors
Users online (5,208)