From 82699a8ac970c4c1e11d0cbde27774a65ef63d73 Mon Sep 17 00:00:00 2001 From: Mads Rasmussen Date: Thu, 4 Feb 2016 20:08:19 +0100 Subject: [PATCH] Fixes: U4-7898 Validation for locked alias still not working --- .../validation/valserverfield.directive.js | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/Umbraco.Web.UI.Client/src/common/directives/components/validation/valserverfield.directive.js b/src/Umbraco.Web.UI.Client/src/common/directives/components/validation/valserverfield.directive.js index 6fe2dfdf08..46fbaf93dd 100644 --- a/src/Umbraco.Web.UI.Client/src/common/directives/components/validation/valserverfield.directive.js +++ b/src/Umbraco.Web.UI.Client/src/common/directives/components/validation/valserverfield.directive.js @@ -12,6 +12,7 @@ function valServerField(serverValidationManager) { link: function (scope, element, attr, ctrl) { var fieldName = null; + var eventBindings = []; attr.$observe("valServerField", function (newVal) { if (newVal && fieldName === null) { @@ -22,11 +23,11 @@ function valServerField(serverValidationManager) { // resubmitted. So once a field is changed that has a server error assigned to it // we need to re-validate it for the server side validator so the user can resubmit // the form. Of course normal client-side validators will continue to execute. - ctrl.$viewChangeListeners.push(function () { + eventBindings.push(scope.$watch('ngModel', function(newValue){ if (ctrl.$invalid) { ctrl.$setValidity('valServerField', true); } - }); + })); //subscribe to the server validation changes serverValidationManager.subscribe(null, fieldName, function (isValid, fieldErrors, allErrors) { @@ -48,10 +49,17 @@ function valServerField(serverValidationManager) { element.bind('$destroy', function () { serverValidationManager.unsubscribe(null, fieldName); }); - } }); + + scope.$on('$destroy', function(){ + // unbind watchers + for(var e in eventBindings) { + eventBindings[e](); + } + }); + } }; } -angular.module('umbraco.directives.validation').directive("valServerField", valServerField); \ No newline at end of file +angular.module('umbraco.directives.validation').directive("valServerField", valServerField);