diff --git a/static/directives/datetime-picker.html b/static/directives/datetime-picker.html index 25f57d701..653c3869a 100644 --- a/static/directives/datetime-picker.html +++ b/static/directives/datetime-picker.html @@ -1,3 +1,3 @@ - + \ No newline at end of file diff --git a/static/js/directives/ui/datetime-picker.js b/static/js/directives/ui/datetime-picker.js index e498850af..9b22c451a 100644 --- a/static/js/directives/ui/datetime-picker.js +++ b/static/js/directives/ui/datetime-picker.js @@ -12,7 +12,7 @@ angular.module('quay').directive('datetimePicker', function () { 'datetime': '=datetime', }, controller: function($scope, $element) { - $scope.entered_datetime = null; + var datetimeSet = false; $(function() { $element.find('input').datetimepicker({ @@ -24,11 +24,15 @@ angular.module('quay').directive('datetimePicker', function () { }); $element.find('input').on("dp.change", function (e) { - $scope.datetime = e.date ? e.date.unix() : null; + $scope.$apply(function() { + $scope.datetime = e.date ? e.date.unix() : null; + }); }); }); - $scope.$watch('entered_datetime', function(value) { + $scope.$watch('selected_datetime', function(value) { + if (!datetimeSet) { return; } + if (!value) { if ($scope.datetime) { $scope.datetime = null; @@ -39,14 +43,16 @@ angular.module('quay').directive('datetimePicker', function () { $scope.datetime = (new Date(value)).getTime()/1000; }); - $scope.$watch('datetime', function(value) { - if (!value) { - $scope.entered_datetime = null; - return; - } + $scope.$watch('datetime', function(value) { + if (!value) { + $scope.selected_datetime = null; + datetimeSet = true; + return; + } - $scope.entered_datetime = moment.unix(value).format('LLL'); - }); + $scope.selected_datetime = moment.unix(value).format('LLL'); + datetimeSet = true; + }); } }; return directiveDefinitionObject;