From 08965982fdf0683e786ed9b7802dbcc7328fa056 Mon Sep 17 00:00:00 2001 From: Barry Date: Sun, 25 Feb 2018 05:50:10 +0000 Subject: [PATCH] Prevent unsaved dialogue appearing when no changes made on FileUpload property editor Addresses this issue in media section (U4-9996) and content (U4-7484) --- .../directives/validation/nodirtycheck.directive.js | 12 ++++++------ .../fileupload/fileupload.controller.js | 3 +++ .../views/propertyeditors/fileupload/fileupload.html | 2 +- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/Umbraco.Web.UI.Client/src/common/directives/validation/nodirtycheck.directive.js b/src/Umbraco.Web.UI.Client/src/common/directives/validation/nodirtycheck.directive.js index e15f62e8df..104736530f 100644 --- a/src/Umbraco.Web.UI.Client/src/common/directives/validation/nodirtycheck.directive.js +++ b/src/Umbraco.Web.UI.Client/src/common/directives/validation/nodirtycheck.directive.js @@ -10,12 +10,12 @@ function noDirtyCheck() { require: 'ngModel', link: function (scope, elm, attrs, ctrl) { - elm.focus(function () { - scope.$watch(function() { - ctrl.$pristine = false; - }); - }); - + var alwaysFalse = { + get: function () { return false; }, + set: function () { } + }; + Object.defineProperty(ctrl, '$pristine', alwaysFalse); + Object.defineProperty(ctrl, '$dirty', alwaysFalse); } }; diff --git a/src/Umbraco.Web.UI.Client/src/views/propertyeditors/fileupload/fileupload.controller.js b/src/Umbraco.Web.UI.Client/src/views/propertyeditors/fileupload/fileupload.controller.js index 3c8170e54b..d8a7710bbb 100644 --- a/src/Umbraco.Web.UI.Client/src/views/propertyeditors/fileupload/fileupload.controller.js +++ b/src/Umbraco.Web.UI.Client/src/views/propertyeditors/fileupload/fileupload.controller.js @@ -130,6 +130,9 @@ function fileUploadController($scope, $element, $compile, imageHelper, fileManag // in the description of this controller, it states that this value isn't actually used for persistence, // but we need to set it so that the editor and the server can detect that it's been changed, and it is used for validation. $scope.model.value = { selectedFiles: newVal.trimEnd(",") }; + + //need to explicity setDirty here as file upload field can't track dirty & we can't use the fileCount (hidden field/model) + $scope.propertyForm.$setDirty(); }); }); diff --git a/src/Umbraco.Web.UI.Client/src/views/propertyeditors/fileupload/fileupload.html b/src/Umbraco.Web.UI.Client/src/views/propertyeditors/fileupload/fileupload.html index 0905de07f9..63810ac610 100644 --- a/src/Umbraco.Web.UI.Client/src/views/propertyeditors/fileupload/fileupload.html +++ b/src/Umbraco.Web.UI.Client/src/views/propertyeditors/fileupload/fileupload.html @@ -31,6 +31,6 @@ - +