cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Frequent Visitor

Difficulties having a button change visibility.

Hello,

 

I have a Context Variable called "currentlyChoosingWorker". It loads as 0.

 

I have set a Gallery's Visibility to be IF(currentlyChoosingWorker,true,false)

I have set a Form's Visiibility to be IF(currentlyChoosingWorker,false,true)

 

I have two buttons that I want to toggle the gallery and form's visibility.

Button1 has onclick: UpdateContext({currentlyChoosingWorker:true})

Button2 has onclick: UpdateContext({currentlyChooosingWorker:false})

Button1 has Visibility: IF(currentlyChoosingWorker,true,false)

Button2 has Visibility: IF(currentlyChoosingWorker,false,true)

 

The buttons both function correctly and toggle their visibility, however the gallery and form do not. If i change the visibility formula to something else and then back to the formulas above it will work until I close powerapps and reopen it fresh and then suddenly it doesnt work anymore. 

 

Is this a bug or am I missing something?

9 REPLIES 9
Highlighted
Advocate II
Advocate II

Re: Difficulties having a button change visibility.

I don't know if this will resolve your issue or not, but I have read several different posts that say to perform UpdateContext twice, like this:

 

For your button1 onclick: UpdateContext({var:false}); UpdateContext({var:true})

For your button2 onclick: UpdateContext({var:true}); UpdateContext({var:false})

 

I was having scenarios where the context wasn't working right until I started doing this. 

Highlighted
Power Participant
Power Participant

Re: Difficulties having a button change visibility.

Hi!

 

My guess is that you initialize the variable to 0, instead of false. Set it to false by a call either to UpdateContext or Set when you start the app.

 

You don't need the IF-statements for setting the visibility, just use the variable stright away, like this:

 

Gallery.Visibility: currentlyChoosingWorker 
Form.Visibility: !currentlyChoosingWorker 

 

If you want, you can use only one button. Let the text change depending on the state and don't care about the visibility. You have to set the text property, by checking the variable, and then you just toggle the value in onClick:

 

 

Button.Text: If(currentlyChoosingWorker, "Show", "Hide")
Button.onClick: UpdateContext({currentlyChoosingWorker:!currentlyChoosingWorker})

You might have to switch the actual texts around to get the effect you want.

 

Good luck!

 

Highlighted
Frequent Visitor

Re: Difficulties having a button change visibility.

Hi BitLord69 thanks for your reply,

 

I like the simplicity of removing the IF statements, and so I have done that, but the result was still the same. When I changed the visibility formula to match your suggestion it worked as intended for the rest of that session. However upon reopening the app it has failed me once again. Surely this must be a bug?

 

I should add that the buttons change visibility correctly, but the Form and Gallery do not, even though they have the same forumulas for visibility as the buttons.

Highlighted
Power Participant
Power Participant

Re: Difficulties having a button change visibility.

Have you set the variable in onStart or onVisible to false (or true depending what you want the start mode to be), not 0, so it's properly set from the beginning? 

 

Can you add a screen dump of your screen when the cursor is in the gallery's or form's Visible-formula?

Highlighted
Advocate II
Advocate II

Re: Difficulties having a button change visibility.

I do not mean to be repeating, but I built a sample app with a gallery and a form.  It has 2 buttons, one called Visible, one called Hidden.  I saved the app, exited, came back in.  I even rebooted my PC.  It works every time.  I run in Edit mode or just run the app and it works. 

Below are screen shots and my code.  Are you using the most current version of PowerApps?

Visible button clickedVisible button clickedHidden button clickedHidden button clicked

Visible button code: UpdateContext({varVisible: false}); UpdateContext({varVisible: true})

 

Hidden button code: UpdateContext({varVisible: true}); UpdateContext({varVisible: false})

Highlighted
Frequent Visitor

Re: Difficulties having a button change visibility.

I appreciate the reply but youre solution of updatingContext twice hasn't seemed to fix my problem. The form and gallery still refuse to operate correctly, unless I modify their visibility formulas and then change them back. Then it will work for the rest of the session but upon closing and reopening the session it fails again.

Highlighted
Frequent Visitor

Re: Difficulties having a button change visibility.

The variable has always been initialized as false, but yes ill post some screen shots in a moment.

Highlighted
Frequent Visitor

Re: Difficulties having a button change visibility.

Capture6.JPGCapture.JPGCapture2.JPGCapture3.JPGCapture4.JPGCapture5.JPG

Highlighted
Power Participant
Power Participant

Re: Difficulties having a button change visibility.

I cannot see anytihng wrong. For reference I'm, attaching two screen shots of one of my apps where I do exactly the same thing, hiding or showing a forn depending on the state of a variable, that changes when I press an icon.

 

Got Skype? Maybe if we do a Skype session you can share your screen and I can have a look at your app. PM me if you want that.

 

An icon changes the state of a boolean variable...An icon changes the state of a boolean variable..... and that boolean variable then decides that visibility of a view form to see the details about a product.. and that boolean variable then decides that visibility of a view form to see the details about a product

Helpful resources

Announcements
secondImage

New Return to Workplace

Reopen responsibly, monitor intelligently, and protect continuously with solutions for a safer work environment.

August 2020 CYST Challenge

Check out the winners of the recent 'Can You Solve These?' community challenge!

Experience what’s next for Power Apps

Join us for an in-depth look at the new Power Apps features and capabilities at the free Microsoft Business Applications Launch Event.

Check this Out

Helpful information

Featuring samples like Return to the Workplace and Emergency Response Applications

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Top Solution Authors
Users online (4,551)