cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Advocate V
Advocate V

How to turn a button visible=false or disabled=true?

I tried to make a button visible=true or disabled=false with the click of another button, but it does not work. Anybody with the same problem?

1 ACCEPTED SOLUTION

Accepted Solutions
Power Apps
Power Apps

You can use context variables to do that. Here's one possible implementation for your scenario (using this screen below):

 Buttons.PNG

We would set the OnSelect property for the "action" buttons to update a context variable:

EnableButton.OnSelect: UpdateContext({ enabled: true })
DisableButton.OnSelect: UpdateContext({ enabled: false })
HideButton.OnSelect: UpdateContext({ visible: false })
ShowButton.OnSelect: UpdateContext({ visible: true })

And in the button that you want to show / hide / disable / enable, you would bind the Disabled and Visible properties to those context variables:

MyButton.Disabled: !enabled
MyButton.Visible: visible

View solution in original post

13 REPLIES 13
Power Apps
Power Apps

You can use context variables to do that. Here's one possible implementation for your scenario (using this screen below):

 Buttons.PNG

We would set the OnSelect property for the "action" buttons to update a context variable:

EnableButton.OnSelect: UpdateContext({ enabled: true })
DisableButton.OnSelect: UpdateContext({ enabled: false })
HideButton.OnSelect: UpdateContext({ visible: false })
ShowButton.OnSelect: UpdateContext({ visible: true })

And in the button that you want to show / hide / disable / enable, you would bind the Disabled and Visible properties to those context variables:

MyButton.Disabled: !enabled
MyButton.Visible: visible

View solution in original post

@CarlosFigueira Thank you for the solution.

Also, thanks to your reply, now I understand what a Variable is.

So double thanks.

Smiley Happy

I have a follow-up question on this. The problem I have is two-fold:

 

1. The visible property not only hides the button during run time, but also in design. (which means to get the button back I either need to use the advanced property pane, or find a way to make it visible again in run time).

2. I wish I had a "on focus" for the screen, so that when the app starts it resets everything to visible. I tried with OnVisible but the button is staying hidden....

 

Do you have a way to do #2?

Community Champion
Community Champion

When you write a formula in the OnVisible property of a Screen, you need to navigate away and return for it to take effect. 

 

That said, here are some tips:

  • All context variables are false by default at the start of the app. Rather than defining your variables in the positive sense, you can define them in the negative sense. So rather than "enable" and "visible" properties, you can call it "disable" and "hidden."
  • Or: If you went with the solution by @CarlosFigueira, then you can add the following formulas in the OnVisible property of your desired Screen:
    UpdateContext({
    enabled: true,
    visible: true
    })
  • OnVisible only triggers once. A more exact name for the property would be "OnNavigationToThisScreen." If you want something to continually force the button to stay a certain way, then you can bind the button itself using App.ActiveScreen. App.ActiveScreen=NameOfScreen checks to see if the screen you're looking at is the active one.

    Button1.Disabled: !(App.ActiveScreen=NameofScreen)
    Button1.Visible: App.ActiveScreen=NameofScreen
Microsoft Employee
@8bitclassroom

Thank you for responding so quickly! I will give that a try and then post results here. Note: I want the button to stay hidden until they close the app. When they reopen the app the button will be visible again, until they click it. They are allowed to use that button only once per session (it's triggering a Microsoft Flow).

 

Thank you again, I promise to let you know if that works today,

Audrie

Community Champion
Community Champion

If you want the button to only be pressed once during the whole app usage, it may be best to use one variable.

 

Button1.OnSelect: UpdateContext({hasbeenpressed: true})
Button1.Disabled: hasbeenpressed

Name the variable whatever you want. It starts off as false. It turns true once it is pressed. There is no way for it to turn back.

 

You may want to put some additional conditions on it so that users don't mess up their one chance:

Button1.OnSelect: If(yourconditionshere, UpdateContext({hasbeenpressed: true}))

Or prevent them from being able to push the button if conditions are not met

Button1.Disabled: hasbeenpressed || !(yourconditionshere)
Microsoft Employee
@8bitclassroom

Thanks for thinking ahead regarding users that might make a mistake. I'm trying it now.

That worked perfectly! You're a genius!

Greetings.

I have a similar question, but based on a drop down box that is prepopulated from sharepoint.

I have a screen, with two data connections.  The permissions are different for each list.

This screen has two prepopulated drop down boxes-  Jobs, PremJobs. 

ALL my users need to see Jobs and only some of them need to see PremJobs.

So far, everything works EXCEPT-

When the PremJobs is automatically disabled based on user permission- I would llike the card to disapear from the screen. 

I can't figure it out.  I think it has to do with the visible control and variables, just don't know the way to go about it.

any help will be appreciated.

thanks so much.

 

Helpful resources

Announcements
Community Conference

Power Platform Community Conference

Check out the on demand sessions that are available now!

News & Announcements

Community Blog

Stay up tp date on the latest blogs and activities in the community News & Announcements.

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Community Highlights

Community Highlights

Check out the Power Platform Community Highlights

Top Solution Authors
Top Kudoed Authors
Users online (2,045)