angular-unsavedChanges
angular-unsavedChanges copied to clipboard
Form not set to pristine after unsaved changes were disregarded
Hello,
First of all thank you for this directive, it's very helpful and easy to use!
The documentation describes the following behaviour:
The module defers to the forms $dirty property as a single source of truth. If dirty, the user is alerted. Disregarding changes resets the form and sets pristine.
I don't see that behaviour happening, and I don't see it in the code either: the form doesn't get set to pristine after the user decided to disregard the unsaved changes.
As a result of this, I get 2 confirmation dialogs. My routeEvent configuration is as follows:
unsavedWarningsConfigProvider.routeEvent = ['$locationChangeStart' ,'$stateChangeStart', 'accordionPanelChangedEvent', 'dossierClosedEvent'];
When I broadcast the dossierClosedEvent, the confirmation dialog is shown. When I decide to ignore the changes, my page redirects, so one of the location-change-events is caught and the confirmation box shows up a second time because the form is still dirty. Will this behaviour be changed in a future version or can I work around it somehow? Currently the behaviour doesn't match with the pasted documentation.
I used the following as a workaround (in my own code, not by changing unsavedChanges.js) for the confirmation dialog showing up twice.
var event = $rootScope.$broadcast("dossierClosedEvent");
if (event.defaultPrevented == false){
//Set all forms to pristine to avoid a second unsaved-dialog
var allForms = unsavedWarningSharedService.allForms();
angular.forEach(allForms, function(item, idx) {
item.$setPristine();
});
//now redirect (which would have previously triggered the second unsaved-dialog)
}
The issue still remains though that the documentation doesn't match with the implementation in the code (setting the form to pristine after the user disregarded the changes)
@facultymatt : Any comments on the issue I posted? My workaround works fine, but I'd like to know if I understood everything correctly.