cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
rhysg
Level: Powered On

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
TML
Level 8

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. 

Super User
Super User

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!

 

rhysg
Level: Powered On

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.

Super User
Super User

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?

TML
Level 8

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.jpgVisible button clickedHidden.jpgHidden button clicked

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

 

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

rhysg
Level: Powered On

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.

rhysg
Level: Powered On

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.

rhysg
Level: Powered On

Re: Difficulties having a button change visibility.

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

Super User
Super User

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.

 

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

Helpful resources

Announcements
thirdimage

Power Automate Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

sixthImage

Power Platform World Tour

Find out where you can attend!

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

fifthimage

Microsoft Learn

Learn how to build the business apps that you need.

Top Kudoed Authors (Last 30 Days)
Users online (1,609)