Fix bug in date time picker that prevents subsequent selection
This commit is contained in:
parent
7d4fed6892
commit
1d600abc5d
2 changed files with 17 additions and 11 deletions
|
@ -1,3 +1,3 @@
|
||||||
<span class="datetime-picker-element">
|
<span class="datetime-picker-element">
|
||||||
<input class="form-control" type="text" ng-model="entered_datetime"/>
|
<input class="form-control" type="text" ng-model="selected_datetime"/>
|
||||||
</span>
|
</span>
|
|
@ -12,7 +12,7 @@ angular.module('quay').directive('datetimePicker', function () {
|
||||||
'datetime': '=datetime',
|
'datetime': '=datetime',
|
||||||
},
|
},
|
||||||
controller: function($scope, $element) {
|
controller: function($scope, $element) {
|
||||||
$scope.entered_datetime = null;
|
var datetimeSet = false;
|
||||||
|
|
||||||
$(function() {
|
$(function() {
|
||||||
$element.find('input').datetimepicker({
|
$element.find('input').datetimepicker({
|
||||||
|
@ -24,11 +24,15 @@ angular.module('quay').directive('datetimePicker', function () {
|
||||||
});
|
});
|
||||||
|
|
||||||
$element.find('input').on("dp.change", function (e) {
|
$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 (!value) {
|
||||||
if ($scope.datetime) {
|
if ($scope.datetime) {
|
||||||
$scope.datetime = null;
|
$scope.datetime = null;
|
||||||
|
@ -39,14 +43,16 @@ angular.module('quay').directive('datetimePicker', function () {
|
||||||
$scope.datetime = (new Date(value)).getTime()/1000;
|
$scope.datetime = (new Date(value)).getTime()/1000;
|
||||||
});
|
});
|
||||||
|
|
||||||
$scope.$watch('datetime', function(value) {
|
$scope.$watch('datetime', function(value) {
|
||||||
if (!value) {
|
if (!value) {
|
||||||
$scope.entered_datetime = null;
|
$scope.selected_datetime = null;
|
||||||
return;
|
datetimeSet = true;
|
||||||
}
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
$scope.entered_datetime = moment.unix(value).format('LLL');
|
$scope.selected_datetime = moment.unix(value).format('LLL');
|
||||||
});
|
datetimeSet = true;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
return directiveDefinitionObject;
|
return directiveDefinitionObject;
|
||||||
|
|
Reference in a new issue