Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Power Apps - Building Power Apps
Unanswered

How do you prevent a variable the OnChange property from triggering when a form is switched from View to Edit?

(0) ShareShare
ReportReport
Posted on by 821 Super User 2025 Season 1

I have a form that starts off in View for the DisplayMode. This is for a couple of reasons. I don't want the owner or admin accidentally editing the form. In addition, only the owner or the admin can edit it so it needs to be in view otherwise. 

 

As an added level of security to prevent accidental edits I set the 'Submit' button to a variable called varChanged and set the OnChange property of every control in the form to that variable  - UpdateContext({varChanged:true}) .

 

Problem I run into is it seems like the switch from View to Edit is triggering the OnChange event in the controls and setting the variable to true which activates the button. Is there a workaround for this?  I only want the 'Update' button to be active if there was an actual change made to the original value.

Categories:
  • WarrenBelz Profile Picture
    146,524 Most Valuable Professional on at
    Re: How do you prevent a variable the OnChange property from triggering when a form is switched from View to Edit?

    @futr_vision ,

    Form.Unsaved at odd times apparently can have issues, but I have found it reliable. There are no other settings other than it simply detects if there are changes on the Form where the current content of a control is not its default value. Have you put YourFormName.Unsaved on a Label and see what the value is as you change things ?

  • futr_vision Profile Picture
    821 Super User 2025 Season 1 on at
    Re: How do you prevent a variable the OnChange property from triggering when a form is switched from View to Edit?

    Yeah. I'm not so sure I want to fiddle with cosmetic issues right now. I did notice, when I opened the app today to test, that my button is not going back to inactive. Seems to indicate that it thinks the forms was changed and unsaved. No idea what would cause that either. Is there a way to see what control might be considered changed?

  • WarrenBelz Profile Picture
    146,524 Most Valuable Professional on at
    Re: How do you prevent a variable the OnChange property from triggering when a form is switched from View to Edit?

    @futr_vision ,

    Not unless you want to start playing with 1-2 second timers and setting a Variable OnTimerEnd that is also a condition of the DisplayMode

     

    Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

    MVP (Business Applications)   Visit my blog Practical Power Apps

  • futr_vision Profile Picture
    821 Super User 2025 Season 1 on at
    Re: How do you prevent a variable the OnChange property from triggering when a form is switched from View to Edit?

    @WarrenBelz 

    This is much, much simpler and it works. I do notice that the button flickers from active to inactive when I choose a gallery item. Is that something I need to live with or something I can mitigate?

  • WarrenBelz Profile Picture
    146,524 Most Valuable Professional on at
    Re: How do you prevent a variable the OnChange property from triggering when a form is switched from View to Edit?

    @futr_vision ,

    Form.Unsaved is only triggered to true when data in a control on the Form is changed. You will not need any of the OnChange code then 

  • futr_vision Profile Picture
    821 Super User 2025 Season 1 on at
    Re: How do you prevent a variable the OnChange property from triggering when a form is switched from View to Edit?

    Thanks. I wonder if I have something else that is triggering it that makes your code not work. I'll need to root through 20+ controls to see what I find. If that yields nothing then it seems like Form.Unsaved might be an option but does it still trigger if nothing is changed?

  • WarrenBelz Profile Picture
    146,524 Most Valuable Professional on at
    Re: How do you prevent a variable the OnChange property from triggering when a form is switched from View to Edit?

    Hi @futr_vision ,

    You can try this on the button

    If(
     FormName.Unsaved,
     DisplayMode.Edit,
     DisplayMode.Disabled
    )

    however I would have thought comparing the current content with the content in the  date source as per my original post would work.

  • futr_vision Profile Picture
    821 Super User 2025 Season 1 on at
    Re: How do you prevent a variable the OnChange property from triggering when a form is switched from View to Edit?

    Hi @WarrenBelz 
    Hope this makes things a bit clearer

    1. When a user enters the screen I set a variable called varFormMode to View
    2. A user can select an item in the gallery and the form populates with a record. The form remains in View mode
    3. A user an then  click the "Edit" button which puts the form in Edit mode
    4. If the user makes a change to any of the fields in the form I would like an "Update" button to go from Disabled to Edit

    I've tried using OnChange of the controls to handle the mode of the Update button but the problem is that when you switch a form from View to Edit it triggers the OnChange for each control which activates the Update button

  • WarrenBelz Profile Picture
    146,524 Most Valuable Professional on at
    Re: How do you prevent a variable the OnChange property from triggering when a form is switched from View to Edit?

    @futr_vision ,

    So  can this clear in my head, where is the OnChange code attached to and what does the code do?

  • futr_vision Profile Picture
    821 Super User 2025 Season 1 on at
    Re: How do you prevent a variable the OnChange property from triggering when a form is switched from View to Edit?

    @WarrenBelz 

    Thanks. The gallery doesn't have any controls using OnChange. All I am doing with the gallery is showing some data from the record. The user clicks on the gallery item and the edit form is populated with the record's full data but the form starts off in View mode. Then the user click an Edit button which puts the form in Edit mode. From there the user makes edits. My goal is to have that Edit button disabled until the user makes a change to one of the controls in the form. In my situation, clicking on a gallery item, which switches the form from View to Edit, also sets the varChanged variable to true.

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

🌸 Community Spring Festival 2025 Challenge 🌸

WIN Power Platform Community Conference 2025 tickets!

Markus Franz – Community Spotlight

We are honored to recognize Markus Franz as our April 2025 Community…

Kudos to the March Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 146,524 Most Valuable Professional

#2
RandyHayes Profile Picture

RandyHayes 76,287 Super User 2024 Season 1

#3
Pstork1 Profile Picture

Pstork1 65,906 Most Valuable Professional

Leaderboard