cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
MRCL
Level 8

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
PowerApps Staff CarlosFigueira
PowerApps Staff

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

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

12 REPLIES 12
PowerApps Staff CarlosFigueira
PowerApps Staff

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

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

SalimMatus
Level: Powered On

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

@CarlosFigueira Thank you for the solution.

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

So double thanks.

Smiley Happy

Power Automate Staff audrieg
Power Automate Staff

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

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?

mr-dang
Level 10

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

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
Power Automate Staff audrieg
Power Automate Staff

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

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

mr-dang
Level 10

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

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
Power Automate Staff audrieg
Power Automate Staff

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

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

Power Automate Staff audrieg
Power Automate Staff

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

That worked perfectly! You're a genius!

Beuferd
Level: Powered On

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

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
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 (6,357)