diff --git a/src/Umbraco.Web.UI.Client/src/common/directives/components/umblockedfield.directive.js b/src/Umbraco.Web.UI.Client/src/common/directives/components/umblockedfield.directive.js index b382fa1c32..204fa7bb86 100644 --- a/src/Umbraco.Web.UI.Client/src/common/directives/components/umblockedfield.directive.js +++ b/src/Umbraco.Web.UI.Client/src/common/directives/components/umblockedfield.directive.js @@ -12,22 +12,6 @@ function LockedFieldDirective($timeout, localizationService) { function link(scope, el, attr, ngModelCtrl) { - - //watch the ngModel so we can manually update the textbox view value when it changes - // this ensures that the normal flow (i.e. a user editing the text box) occurs so that - // the parsers, validators and viewchangelisteners execute - scope.$watch("ngModel", function (newValue, oldValue) { - if (newValue !== oldValue) { - //Hack: in order for the pipeline to execute for setViewValue, the underlying $modelValue cannot - // match the value being set with the newValue, so we'll se it to undefined first. - // We could avoid this hack by setting the ngModel of the lockedField input field to a custom - // scope object, but that would mean we'd have to watch that value too in order to set the outer - // ngModelCtrl.$modelValue. It's seems like less overhead to just do this and not have 2x watches. - scope.lockedFieldForm.lockedField.$modelValue = undefined; - scope.lockedFieldForm.lockedField.$render(); - } - scope.lockedFieldForm.lockedField.$setViewValue(scope.lockedFieldForm.lockedField.$modelValue); - }); function activate() { diff --git a/src/Umbraco.Web.UI.Client/src/common/directives/components/validation/valregex.directive.js b/src/Umbraco.Web.UI.Client/src/common/directives/components/validation/valregex.directive.js index bc69d1cd02..7bc3c6b877 100644 --- a/src/Umbraco.Web.UI.Client/src/common/directives/components/validation/valregex.directive.js +++ b/src/Umbraco.Web.UI.Client/src/common/directives/components/validation/valregex.directive.js @@ -14,6 +14,7 @@ function valRegex() { var flags = ""; var regex; + var eventBindings = []; attrs.$observe("valRegexFlags", function (newVal) { if (newVal) { @@ -38,6 +39,12 @@ function valRegex() { } }); + eventBindings.push(scope.$watch('ngModel', function(newValue, oldValue){ + if(newValue && newValue !== oldValue) { + patternValidator(newValue); + } + })); + var patternValidator = function (viewValue) { if (regex) { //NOTE: we don't validate on empty values, use required validator for that @@ -58,8 +65,14 @@ function valRegex() { } }; - ctrl.$parsers.push(patternValidator); + scope.$on('$destroy', function(){ + // unbind watchers + for(var e in eventBindings) { + eventBindings[e](); + } + }); + } }; } -angular.module('umbraco.directives.validation').directive("valRegex", valRegex); \ No newline at end of file +angular.module('umbraco.directives.validation').directive("valRegex", valRegex); diff --git a/src/Umbraco.Web.UI.Client/src/views/content/create.html b/src/Umbraco.Web.UI.Client/src/views/content/create.html index d3bc28bc55..c40fb39351 100644 --- a/src/Umbraco.Web.UI.Client/src/views/content/create.html +++ b/src/Umbraco.Web.UI.Client/src/views/content/create.html @@ -1,9 +1,9 @@ -