diff --git a/src/Umbraco.Web.UI.Client/src/common/directives/valpropertymsg.directive.js b/src/Umbraco.Web.UI.Client/src/common/directives/valpropertymsg.directive.js index 8fe135951c..c5dca948b2 100644 --- a/src/Umbraco.Web.UI.Client/src/common/directives/valpropertymsg.directive.js +++ b/src/Umbraco.Web.UI.Client/src/common/directives/valpropertymsg.directive.js @@ -115,6 +115,11 @@ function valPropertyMsg(serverValidationService) { }); } }); + + //when the element is disposed we need to unsubscribe! + element.bind('$destroy', function () { + serverValidationService.unsubscribe(currentProperty, ""); + }); } }; } diff --git a/src/Umbraco.Web.UI.Client/src/common/directives/valserver.directive.js b/src/Umbraco.Web.UI.Client/src/common/directives/valserver.directive.js index 23bad62138..edfb151397 100644 --- a/src/Umbraco.Web.UI.Client/src/common/directives/valserver.directive.js +++ b/src/Umbraco.Web.UI.Client/src/common/directives/valserver.directive.js @@ -52,6 +52,11 @@ function valServer(serverValidationService) { ctrl.errorMsg = ""; } }); + + //when the element is disposed we need to unsubscribe! + element.bind('$destroy', function () { + serverValidationService.unsubscribe(currentProperty, fieldName); + }); } }; } diff --git a/src/Umbraco.Web.UI.Client/src/common/directives/valtogglemsg.directive.js b/src/Umbraco.Web.UI.Client/src/common/directives/valtogglemsg.directive.js index 779eb0fb37..a449bc1bb8 100644 --- a/src/Umbraco.Web.UI.Client/src/common/directives/valtogglemsg.directive.js +++ b/src/Umbraco.Web.UI.Client/src/common/directives/valtogglemsg.directive.js @@ -33,7 +33,7 @@ function valToggleMsg() { var showValidation = false; var hasError = false; - //add a watch to the validator for the value (i.e. $parent.myForm.value.$error.required ) + //add a watch to the validator for the value (i.e. myForm.value.$error.required ) scope.$watch(formCtrl.$name + "." + attr.valMsgFor + ".$error." + attr.valToggleMsg, function (isInvalid, oldValue) { hasError = isInvalid; if (hasError && showValidation) { diff --git a/src/Umbraco.Web.UI.Client/src/common/services/servervalidation.service.js b/src/Umbraco.Web.UI.Client/src/common/services/servervalidation.service.js index 90e913b59c..601725b923 100644 --- a/src/Umbraco.Web.UI.Client/src/common/services/servervalidation.service.js +++ b/src/Umbraco.Web.UI.Client/src/common/services/servervalidation.service.js @@ -37,6 +37,17 @@ function serverValidationService() { } }, + unsubscribe: function(contentProperty, fieldName) { + if (!contentProperty) { + return; + } + callbacks = _.reject(callbacks, function (item) { + return item.propertyAlias == contentProperty.alias && + (item.fieldName == fieldName || + ((item.fieldName == undefined || item.fieldName == "") && (fieldName == undefined || fieldName == ""))); + }); + }, + /** * @ngdoc function * @name getCallbacks diff --git a/src/Umbraco.Web.UI.Client/src/views/content/contentedit.controller.js b/src/Umbraco.Web.UI.Client/src/views/content/contentedit.controller.js index c5d6e1c5a8..97ba8a4602 100644 --- a/src/Umbraco.Web.UI.Client/src/views/content/contentedit.controller.js +++ b/src/Umbraco.Web.UI.Client/src/views/content/contentedit.controller.js @@ -17,6 +17,7 @@ function ContentEditController($scope, $routeParams, contentResource, notificati * @description * A function to handle what happens when we have validation issues from the server side */ + function handleSaveError(err) { //When the status is a 403 status, we have validation errors. //Otherwise the error is probably due to invalid data (i.e. someone mucking around with the ids or something). @@ -24,7 +25,7 @@ function ContentEditController($scope, $routeParams, contentResource, notificati if (err.status == 403) { //now we need to look through all the validation errors if (err.data && err.data.ModelState) { - + //get a list of properties since they are contained in tabs var allProps = []; for (var i = 0; i < $scope.content.tabs.length; i++) { @@ -54,6 +55,9 @@ function ContentEditController($scope, $routeParams, contentResource, notificati //add a generic error for the property, no reference to a specific field serverValidationService.addError(contentProperty, "", err.data.ModelState[e][0]); } + + //add to notifications + notificationsService.error("Validation", err.data.ModelState[e][0]); } }