From 54aa1924c0cee7d39f75fdc8ec32fd6ee413ee12 Mon Sep 17 00:00:00 2001 From: Shannon Date: Tue, 12 Feb 2019 13:55:50 +1100 Subject: [PATCH] ok, properly fixes dirty tracking on the tags editor --- .../tags/umbtagseditor.directive.js | 36 +++++++++---------- 1 file changed, 17 insertions(+), 19 deletions(-) diff --git a/src/Umbraco.Web.UI.Client/src/common/directives/components/tags/umbtagseditor.directive.js b/src/Umbraco.Web.UI.Client/src/common/directives/components/tags/umbtagseditor.directive.js index 5131dc3dcb..40def728ed 100644 --- a/src/Umbraco.Web.UI.Client/src/common/directives/components/tags/umbtagseditor.directive.js +++ b/src/Umbraco.Web.UI.Client/src/common/directives/components/tags/umbtagseditor.directive.js @@ -55,7 +55,7 @@ vm.isLoading = false; //ensure that the models are formatted correctly - configureViewModel(); + configureViewModel(true); // Set the visible prompt to -1 to ensure it will not be visible vm.promptIsVisible = "-1"; @@ -140,17 +140,8 @@ if (changes.value) { if (!changes.value.isFirstChange() && changes.value.currentValue !== changes.value.previousValue) { - if (initLoad) { - //this occurs if we have to re-format the model on the init load, so set the flag to false - //so the next time it actually changes we process it. - initLoad = false; - //we need to reset the form since it actually hasn't changed but it will be detected as changed - vm.tagEditorForm.$setPristine(); - } - else { - configureViewModel(); - reValidate(); - } + configureViewModel(); + reValidate(); } } } @@ -164,14 +155,19 @@ $element.find('.tags-' + vm.htmlId).typeahead('destroy'); } - function configureViewModel() { + function configureViewModel(isInitLoad) { if (vm.value) { if (angular.isString(vm.value) && vm.value.length > 0) { if (vm.config.storageType === "Json") { //json storage vm.viewModel = JSON.parse(vm.value); - updateModelValue(vm.viewModel); - return; + + //if this is the first load, we are just re-formatting the underlying model to be consistent + //we don't want to notify the component parent of any changes, that will occur if the user actually + //changes a value. If we notify at this point it will signal a form dirty change which we don't want. + if (!isInitLoad) { + updateModelValue(vm.viewModel); + } } else { //csv storage @@ -185,16 +181,18 @@ return self.indexOf(v) === i; }); - updateModelValue(vm.viewModel); - return; + //if this is the first load, we are just re-formatting the underlying model to be consistent + //we don't want to notify the component parent of any changes, that will occur if the user actually + //changes a value. If we notify at this point it will signal a form dirty change which we don't want. + if (!isInitLoad) { + updateModelValue(vm.viewModel); + } } } else if (angular.isArray(vm.value)) { vm.viewModel = vm.value; } } - //if we've made it here we haven't had to re-format the model so we'll set this to false - initLoad = false; } function updateModelValue(val) {