Skip to content

Commit 9498448

Browse files
Merge pull request #388 from vkrizan/313-datepicker-typed-values
Fix pfDatepicker to clear date and allow incomplete input dates
2 parents cbd66f1 + 632a73a commit 9498448

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/form/datepicker/datepicker.directive.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,16 +56,23 @@ angular.module('patternfly.form').directive('pfDatepicker', function () {
5656
element.datepicker('update', $scope.date);
5757

5858
//Change happened on the date picker side. Update the underlying date model
59-
element.datepicker($scope.date).on('changeDate', function (elem) {
59+
element.datepicker($scope.date).on('changeDate clearDate', function (elem) {
6060
$scope.$apply(function () {
6161
$scope.date = elem.date;
6262
});
6363
});
6464

6565
//Update the date picker if there is a change on the date model
6666
$scope.$watch('date', function (newValue, oldValue) {
67+
var elemDate;
6768
if (oldValue !== newValue) {
68-
element.datepicker('update', newValue);
69+
elemDate = element.datepicker('getDate');
70+
if (!elemDate || !newValue || elemDate.getTime() !== newValue.getTime()) {
71+
//Update date picker value only when there is a change
72+
//to avoid resetting when a wrong date is typed
73+
//into input.
74+
element.datepicker('update', newValue);
75+
}
6976
}
7077
});
7178
}

0 commit comments

Comments
 (0)