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 / toggle On Change prope...
Power Apps
Answered

toggle On Change property triggered at every FormDisplay mode change?

(2) ShareShare
ReportReport
Posted on by 203

Hello,

there is a property on toggle I really cannot grab - on Change.

I assigned a variable to it, the toggle will switch on and off based on conditions and on change update the variable. And I would like to keep it this way - the variable update should only be triggered at the moment where the value gets changed.

 

However, every time I go from the form view mode to edit mode the OnChange property is re-read and the variable gets re-assigned according to the toggle value, even though the toggle has not been changed.

 

Is there a workaround? I cannot use the "OnSelect" property as it is not triggered by a calculation (at least that's what I have experienced).

 

Thanks!

Kind regards

Valeria

 

Categories:
I have the same question (0)
  • RandyHayes Profile Picture
    76,299 Super User 2024 Season 1 on at

    @ValeriaBreve 

    Yes, consider not using variables for this!  A variable in PowerApps should only be used when there is a need for a snapshot that cannot be attained otherwise.  

    In your case, there is no need to set a variable when the toggle is changed.  You can simply reference the toggle to get the value any time you want.  Ex:  yourToggle.Value is all you need in any place in your app.  Controls are global, so you can get this anywhere.

    Creating a variable to gather a value of a control is just extra work for you to do and maintain.

     

    I hope this is helpful for you.

  • ValeriaBreve Profile Picture
    203 on at

    Hi Randy, the thing is that I want to be able to capture the moment when the toggle is set to "true" (hence the "OnChange" property) to have a popup open and inform the user about some stuff, then the user closes the popup, the variable goes back to its "False" state, and I am good with it.

    I do not want a permanent check that the toggle value is true. What happens today is that it works as expected, only to have the variable set back to its "true" state (when the toggle value is true) every time the form changes its display mode, meaning that the user keeps getting the popup (1 time is definitely enough). 

    Does this make sense? Otherwise yes I would not have used variables but just evaluated the toggle status. Thanks!

     

     

  • RandyHayes Profile Picture
    76,299 Super User 2024 Season 1 on at

    @ValeriaBreve 

    Yes, that makes sense!

    So the only reason that the toggle would change value is if the default property changes (or, obviously, if the user changes it).  So, I would look to the default property of your toggle to determine where its value is coming from and how it is changing, as that would cause the issue.

  • ValeriaBreve Profile Picture
    203 on at

    Hi Randy, the default property is a calculation

     

    Value(LabelTotalQuantity.Text)>1000 And DataCardValueTransp.Value=true

    based on other form values.

     

    And OnChange is the variable update

    If(DataCardValue154.Value,UpdateContext({showDFT:1}),UpdateContext({showDFT:0}))

     

    So what does PowerApp consider as a Change in a Toggle? I would suppose a change in its Value... (from true to false or false to true). But then in this case I am not changing anything whenever I either submit the form or when I change it to view mode, and still the variable gets reset to "1", as if the fact of just changing the Displaymode of the form would force the OnChange property to get triggered and recalculate. I found the same for OnCheck and OnUncheck, the only one that does not have this behaviour seems to be "OnSelect". However, "Onselect" only seems to get triggered by the user manually switching the toggle - the default value changing based on the calculation does not trigger it.

    Have you ever experienced this? Do you maybe have a workaround? My users are going to go crazy with the popup showing every time the form status changes. Thanks!

     

     

     

  • RandyHayes Profile Picture
    76,299 Super User 2024 Season 1 on at

    @ValeriaBreve 

    Keep in mind what I mentioned about Excel - PowerApps is just like it!  Why do I point this out?  Because just like in Excel, if any cell value changes and there are formulas in other cells that reference that cell, they will all re-evaluate.  The same thing happens in PowerApps.  So, performing calculations based on another control - they will always re-evaluate if there is any change to the other controls they reference.  This is one of the awesome features for PowerApps, but very frustrating to those thinking more "development" like.  

     

    So, in your case, changing the DisplayMode is not going to cause any particular re-evaluations, unless you have formulas that reference the DisplayMode of the form.

    BUT, the underlying value of the Default is going to change what the toggle shows and thus an action that is performed.

     

    And yes, the OnSelect action will only occur if a user clicks on the control.  OnCheck, OnUnCheck and OnChange are all different actions.  Some controls will perform those actions when values change, others not.

     

    So back to the story - Is this toggle part of a field of your datasource?  Or is it just an added toggle?

    If just added, then where in the formula-chain is the underlying datasource column value?

    Does LabelTotalQuantity.Text come from the datasource column?  Or does DataCardValueTransp.Value come from it?

  • ValeriaBreve Profile Picture
    203 on at

    Hi Randy, in my case the OnChange property is triggered even when no other value changes - so even when both LabelTotalQuantity.Text and DataCardValueTransp.Value do not change their value,  the recalculation takes place when the form changes its displaymode. 

     

    The toggle is part of my datasource, I am not displaying its value from the datasource but I want to capture its value as calculated in PowerApp (I made it "view" mode for all form Display Modes).

     

    LabelTotalQuantity.Text is calculated from several card values- which come in their turn from the datasource. DataCardValueTransp.Value comes from the datasource (or from user action inbetween). 

     

    I see that the value recalculates every time I change one of the card values, like Excel, and this is normal and expected. But when nothing changes? And why on the DisplayMode change? Thanks!

  • ValeriaBreve Profile Picture
    203 on at

    Hello, does anybody have any idea why I am experiencing such a behavior, when nothing in my fields changes? Many thanks for your help!

  • Verified answer
    ValeriaBreve Profile Picture
    203 on at

    If you ever reach this post...I have raised the question with Microsoft, below is their statement. So solution should be available in the future.

     

    “There are a few controls whose OnChange rule runs whenever data changes (on initialization, on items change, on default value change, on user interaction); these are ComboBox, DatePicker, Slider, and Toggle. All other controls only run their OnChange rule on user interaction.

     

    To bring these controls into line with the remaining controls, we are planning to add a preview flag to the settings page to enable strict onchange handling.”

     

     

  • bradt30h Profile Picture
    134 on at

    Hi Valeria,

     

    Thanks for your sharing. I face the same issue. What was your workaround while waiting the solution by Microsoft?

  • LennartWalldén Profile Picture
    181 on at

    Hi @bradt30h,

    Maybe there are better solutions, but I compare the actual value in SP with the value of the control.
    If there is no difference, I don't execute the rest of the OnChange. 

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 Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the July Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 379 Most Valuable Professional

#2
11manish Profile Picture

11manish 203 Super User 2026 Season 2

#3
MS.Ragavendar Profile Picture

MS.Ragavendar 128 Super User 2026 Season 2

Last 30 days Overall leaderboard