Hello,
I am currently building a simple form with a reminder pop up to select Save in the case a users tries to leave a page without saving. I am utilizing a variable varWarrantiesChanges that updates to true anytime a change is made without saving (OnChange property of my fields). If they don't make any changes in the form and navigate back, it goes back as expected as varWarrantiesChanges remains false. If they make a change without saving and hit back, varWarrantiesChanges is true and the popup comes up.
The issue I'm having is when they do select the save button, the following OnSelect() code is run:
SubmitForm(Form1);
UpdateContext({varWarrantiesChanges: false});
So the varWarrantiesChanges flag should be set back to false, and the popup should remain hidden when hitting the back button. When selecting save and running the OnSelect() code above however, varWarrantiesChanges updates to false for a split second and then updates right back to true for some reason. I assume it's something that SubmitForm() is doing, but I cannot figure out what it might be/what the fix is. Maybe SubmitForm() technically changes a field when submitting which triggers the OnChange? If anyone has a solution or a workaround for what I'm trying to do that would be much appreciated.
Solved my own problem - for those finding this and dealing with the same thing, use the Form property UnSaved to create form behavior. I did If(Form1.Unsaved, UpdateContext({varWarrantiesChanges: true}), Back()). This worked as expected.
Put the UpdateContext variable in the OnSuccess property of the form. That way it will only change if the form is successfully saved. There is almost never a reason to chain commands after activating the SubmitForm(). You don't want a second function to execute if the form is not successfully saved.
If you are leaving that screen and coming back to it, use the Set() function to create a global variable as the UpdateContext() function resets if you leave the screen.
I actually did do that OnSuccess but the error remained. I used context variables on purpose as I have multiple forms that require the same behavior, I could try with global variables to see if that fixes it though. I was perplexed as to why it wouldn't work with the OnSuccess code....
This training provides practical hands-on experience in creating Power Apps solutions in a full-day of instructor-led App creation workshop.
User | Count |
---|---|
188 | |
56 | |
50 | |
37 | |
36 |
User | Count |
---|---|
270 | |
91 | |
83 | |
76 | |
75 |