From ecf9c0adb47160d590d628360e9ccbd8ce3ee0c4 Mon Sep 17 00:00:00 2001 From: Mike Chambers Date: Thu, 11 Oct 2018 10:13:47 +0100 Subject: [PATCH] Update datepickerController to add onValueChanged function adding onValueChanged method to capture serverside Model Changes, clearing flag using c# System.DateTime.MinValue. --- .../datepicker/datepicker.controller.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/Umbraco.Web.UI.Client/src/views/propertyeditors/datepicker/datepicker.controller.js b/src/Umbraco.Web.UI.Client/src/views/propertyeditors/datepicker/datepicker.controller.js index 1e0493e8f1..70c6bb4531 100644 --- a/src/Umbraco.Web.UI.Client/src/views/propertyeditors/datepicker/datepicker.controller.js +++ b/src/Umbraco.Web.UI.Client/src/views/propertyeditors/datepicker/datepicker.controller.js @@ -38,6 +38,22 @@ function dateTimePickerController($scope, notificationsService, assetsService, a }; $(document).bind("click", $scope.hidePicker); + //here we declare a special method which will be called whenever the value has changed from the server + //this is instead of doing a watch on the model.value = faster + $scope.model.onValueChanged = function (newVal, oldVal) { + if (newVal != oldVal) { + //check for c# System.DateTime.MinValue being passed as the clear indicator + var minDate = moment('0001-01-01'); + var newDate = moment(newVal); + + if (newDate.isAfter(minDate)) { + applyDate({ date: moment(newVal) }); + } else { + $scope.clearDate(); + } + } + }; + //handles the date changing via the api function applyDate(e) { angularHelper.safeApply($scope, function() {