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.
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 ?
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?
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
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?
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
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?
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.
Hi @WarrenBelz
Hope this makes things a bit clearer
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
So can this clear in my head, where is the OnChange code attached to and what does the code do?
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
146,524
Most Valuable Professional
RandyHayes
76,287
Super User 2024 Season 1
Pstork1
65,906
Most Valuable Professional