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

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / How do you prevent a v...
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 831 Moderator

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:
I have the same question (0)
  • NickMerrick Profile Picture
    419 Super User 2024 Season 1 on at

    why would you have a variable in every controls on change? if its something you don't want edited, make the form open in view mode, then check if the active user is the owner/admin, if they are, show a button called edit visible. when the button is pressed, have the form change from view to edit, and replace the edit button with a submit button to patch the record.

  • futr_vision Profile Picture
    831 Moderator on at

    I am thinking I might take that approach. I was simply thinking that if a change was not made to any of the fields then there is no reason to submit the form. I would leave the Submit button in disabled mode in this case. If a change was made then I would put the button in edit mode. Maybe the answer is to go the route you suggested. The Submit button is disabled until the form is switched to edit more and maybe a happy medium would be to disallow a submit and pop an error message if no fields are changed? 

  • NickMerrick Profile Picture
    419 Super User 2024 Season 1 on at

    so forms have a variable built in to detect changes called Unsaved. you could set the submit button to be disabled or not visible based on that variable. you would call it as FormName.Unsaved, returns false if no changes and true if there are changes.

     

    just be careful as if the datacardvalues value is different than the referenced records value it will show as true no matter what, so no custom formatting, gotta be exactly the same.

  • WarrenBelz Profile Picture
    153,051 Most Valuable Professional on at

    Hi @futr_vision ,

    The easiest way is to compare the current content with the underlying data (example Combo Box with .Value as output writing to Choice/Lookup field) ) - OnChange 

    If(
     Self.Selected.Value <> ThisItem.FieldName.Value,
     UpdateContext({varChanged:true})
    )
     

     

  • futr_vision Profile Picture
    831 Moderator on at

    Finally got this all wired up it appears that when you select a different gallery item it triggers the OnChange of the controls. Does that sound right? Is there any workaround for that?

  • WarrenBelz Profile Picture
    153,051 Most Valuable Professional on at

    @futr_vision ,

    Are you are referring to gallery controls and unsaved data in them or simply that OnChange triggers, If the second one, the answer is the same.

  • futr_vision Profile Picture
    831 Moderator on at

    If I click a gallery item it sets varChanged to true

  • WarrenBelz Profile Picture
    153,051 Most Valuable Professional on at

    @futr_vision ,

    What type of control in the gallery in the OnChange set on and is that control displaying a field value ?

  • futr_vision Profile Picture
    831 Moderator on at

    @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.

  • WarrenBelz Profile Picture
    153,051 Most Valuable Professional on at

    @futr_vision ,

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

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 711 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 319 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard