web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Disable a button after...
Power Apps
Unanswered

Disable a button after it is pressed once

(0) ShareShare
ReportReport
Posted on by 25

Hello community;

 

I have created a voting app and i have a button and I want to make sure once a user presses it once , the button will be disabled so that a user can only vote once not multiple times.

 

I followed this guide but i got some errors.

https://powerusers.microsoft.com/t5/Building-Power-Apps/Disabling-a-button-once-it-is-pressed/td-p/293189

 

Team, can anyone suggests something.

 

disable button.PNG

 

Thank you.

 

 

Categories:
I have the same question (0)
  • Vijay Tailor Profile Picture
    2,961 on at

    Hi @Raou ,

    YOu can Use like below.

    Create A new Global variable like - Use the below code OnSelect Property of Button.

    Set(IsVoted,true)

     and use the conditional step for the display mode of the button.
    like below

    if(IsVoted,DisplayMode.Disable,DisplayMode.Edit)

    Thanks,

    Please click "Accept as Solution" if my post answered your question so that others may find it more quickly. If you found this post helpful consider giving it a "Thumbs Up."-Vijay

  • BrianS Profile Picture
    2,407 Super User 2024 Season 1 on at

    This will work, however, it will not keep someone from closing the app and then re-opening it and voting again. If you want to make sure people only vote once, you will need to look thru the data and make sure they haven't voted yet.

    Something like:

    If(IsBlank(LookUp( dataSource, User().email=List_email)),

    SubmitForm(Vote),

    Notify("Sorry - you already voted",NotificationType.Warning))

    where List_email is where their email is stored in dataSource

  • Raou Profile Picture
    25 on at

    Thank you @VijayTailor for your response.

     

    However, the button is still visible.

    I put below code in "OnSelect" property 

    Set(IsVoted,true)

     and 

    if(IsVoted,DisplayMode.Disable,DisplayMode.Edit)

    under DisplayMode

     

    I can still see the button 

    display mode.png

  • Raou Profile Picture
    25 on at

    Hey @BrianS 

     

    I tested it and it works and I can receive the warning message successfully.

     

    However, the button is not disabled and if I click on the button, my voting will still be saved in the datasource.

     

    Any advise on this.

     

    Thank you.

  • BrianS Profile Picture
    2,407 Super User 2024 Season 1 on at

    First - regarding the visibility of the button. If you want the button to not show, put the code in the Visible property. All you need is the variable, not any test if your variable is Boolean. If you are using Set(IsVoted,true) then you can just put !IsVoted in the Visible property and the button will not be visible once it is pressed.

    The Disabled property will show the button, but will not allow it to function, and it will use a separate set of colors. This is often preferable, but in your case the Visible is fine.

    The code I presented earlier to test for the presence of voting in the list should keep the data from being written if there is already a vote in the list. It would not disable the button - that would be up to the code above. If it is recording the data then there is an error in the code and it is not evaluating correctly.

  • RThind Profile Picture
    on at

    You have spelt it as 'Disable' so its incorrect. It should be:

    If(IsVoted, DisplayMode.Disabled, DisplayMode.Edit )

  • Paladin Profile Picture
    34 on at

    You could also set the button DisplayMode to the following.

    If (Self.Pressed,DisplayMode.Disabled)

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Launch!

Jump in, show your community spirit, and win prizes!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the May Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
Valantis Profile Picture

Valantis 483

#2
WarrenBelz Profile Picture

WarrenBelz 399 Most Valuable Professional

#3
11manish Profile Picture

11manish 327

Last 30 days Overall leaderboard