Skip to content

Commit 34824ff

Browse files
author
Per Ploug Krogslund
committed
Confirm navigating away from unsaved content
1 parent 6f28a0a commit 34824ff

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

src/Umbraco.Web.UI.Client/src/common/directives/validation/valformmanager.directive.js

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* Another thing this directive does is to ensure that any .control-group that contains form elements that are invalid will
1313
* be marked with the 'error' css class. This ensures that labels included in that control group are styled correctly.
1414
**/
15-
function valFormManager(serverValidationManager) {
15+
function valFormManager(serverValidationManager, $rootScope, $log, notificationsService) {
1616
return {
1717
require: "form",
1818
restrict: "A",
@@ -51,6 +51,25 @@ function valFormManager(serverValidationManager) {
5151
scope.$on(savedEvent, function (ev, args) {
5252
element.removeClass(className);
5353
});
54+
55+
56+
var locationEvent = $rootScope.$on('$locationChangeStart', function(event, newUrl){
57+
if (!formCtrl.$dirty) {
58+
return;
59+
}
60+
var path = newUrl.split("#")[1];
61+
var msg = {view: "confirmroutechange", args: {path: path, listener: locationEvent}};
62+
notificationsService.add(msg);
63+
64+
event.preventDefault();
65+
return;
66+
});
67+
68+
scope.$on('$destroy', function() {
69+
if(locationEvent){
70+
locationEvent();
71+
}
72+
});
5473
}
5574
};
5675
}

0 commit comments

Comments
 (0)