Unsaved changes warning can be misleading

  • 3
  • Problem
  • Updated 5 years ago
  • Acknowledged
  • (Edited)
The new "Warn users if page has unsaved changes" feature has been extremely helpful.  Unfortunately, we are running in to an issue with pages that have "helper" models that will never be saved.  In this case, if the user doesn't change anything on the page, they still encounter the warning because there is a model (manipulated programmatically client side) that triggers the warning.

Would it be possible to add a "track" changes option to each model that would be incorporated in the "unsaved changes" check on beforeunload?  Or some other similar concept or is there a workaround that could be used?

I have granted login access.  Sample page is SampleUnsavedChangesWarningRepro

Steps to reproduce:
1) Create a tab page on Account
2) Add a JS Inline resource with the following code: 
** Note that the same behavior exists if the model is defined in page builder and then manipulated (e.g. createRow/updateRow) in code
// The below is for demonstration purposes only
// and is not to be considered production consumable code
// Only intended to demonstrate unsaved warning will be triggered
var $ = skuid.$;
var clientSideModel = new skuid.model.Model();
clientSideModel.id = 'clientSideModel';
clientSideModel.recordsLimit = 1;
clientSideModel.fields = [
        { id: 'Color__c' }
var row = clientSideModel.createRow();
clientSideModel.updateRow(row, 'Color__c', 'blue');
3) Preview the page
4) Navigate away by choosing any link available making sure to say on the current window

Actual Result:
Unsaved changes will be lost warning is encountered

Desired/Expected Behavior
No warning is encountered

Thank you!
Photo of Barry Schnell

Barry Schnell, Champion

  • 18,456 Points 10k badge 2x thumb

Posted 6 years ago

  • 3
Photo of Rob Hatch

Rob Hatch, Official Rep

  • 45,308 Points 20k badge 2x thumb
Barry - we have seen this problem in our work. There are places where helper models really should be ignored by the Unsaved Changes warning.  

We'd reccomend either turning the unsaved changes off in those pages,  or writing your own Warning tied to the onUnload event - and looking at the "has changes" property of the modelds you care about. 

We are concerned about model property bloat and have not yet decided whether we should tune the saved changes warning so precisely. 

Thanks for sending us the details though... 
Photo of Barry Schnell

Barry Schnell, Champion

  • 18,456 Points 10k badge 2x thumb
Thanks Rob.  The custom beforeonload was my backup plan so I'll go with that.

Regarding model property bloat, completely understand.  One other option that I can think of is adding a page property for "Models to Track."  It could be conditionally available in the builder if "warn unsaved changes" is enabled or could just be merged in to a single property as a multi-picklist similar to "save/cancel models" ui in the builder.  This would avoid adding more properties to models but still provide for the declarative approach to eliminating helper models from unsaved changes.
Photo of Barry Schnell

Barry Schnell, Champion

  • 18,456 Points 10k badge 2x thumb
Hey Rob.  Realized that my suggestion above regarding a new page property wouldn't account for programmatically created models since in order to pick it from a multipick list the model would have to be declaratively defined on the page.  In that case of models created in code, possibly a new api to registerModelToTrack or a parameter on model constructor or model register.

Just thinking out loud, thanks for listening :)
Photo of Rob Hatch

Rob Hatch, Official Rep

  • 45,308 Points 20k badge 2x thumb
No worries Barry. Thanks for offering up the suggestions.  We really appreciate your willingness to help us push the product further..
Photo of Menachem Shanowitz

Menachem Shanowitz

  • 1,094 Points 1k badge 2x thumb
Perhaps, in addition to the page setting, a model setting can be made that the unsaved error warning will not show for changes made on that model.

I find that I occasionally use a model for UI rendering purposes which triggers the warning unnecessarily but I don't want to shut the warning off on that page either.