angular-ui / bootstrap

PLEASE READ THE PROJECT STATUS BELOW. Native AngularJS (Angular) directives for Bootstrap. Smaller footprint (20kB gzipped), no 3rd party JS dependencies (jQuery, bootstrap JS) required. Please read the README.md file before submitting an issue!
http://angular-ui.github.io/bootstrap/
MIT License
14.28k stars 6.73k forks source link

Time picker defaults to current DateTime on error, instead of keeping the selected date. #6152

Open EduardsBrown opened 8 years ago

EduardsBrown commented 8 years ago

Bug description:

When you enter an invalid hour such as 0 or empty, the DatePicker entry gets reset and defaults to current DateTime.

Selection:

image

DateTime Resets:

image

Default Used:

image

I believe it should keep the selected DateTime.

Version of Angular, UIBS, and Bootstrap

angular: 1.5.0 bootstrap-ui-datetime-picker: 1.2.0 bootstrap-sass: 3.3.1

I've also tried on latest versions, and got the same result.

Angular: The issue lives inside timepicker.js

var invalidate = function(invalidHours, invalidMinutes, invalidSeconds) {
      ngModelCtrl.$setViewValue(null);
      ngModelCtrl.$setValidity('time', false);
      if (angular.isDefined(invalidHours)) {
        $scope.invalidHours = invalidHours;
      }
      if (angular.isDefined(invalidMinutes)) {
        $scope.invalidMinutes = invalidMinutes;
      }
      if (angular.isDefined(invalidSeconds)) {
        $scope.invalidSeconds = invalidSeconds;
      }
};

Specifically: ngModelCtrl.$setViewValue(null);

Reproduced bug plnkr: https://embed.plnkr.co/SZC1uUaXDcE9CLSb9JiI/

Possible solution plnkr: https://embed.plnkr.co/fj1Ckcg2EcC9ZTaW9Zl1/

(Sometimes when you open the plnkrs, they give Service Unavailable error, please close the plnkr and click on the link again, and it should work).

I am willing to make the change and submit a pull request, if this is fine?

EduardsBrown commented 8 years ago

I've tried to fix this by branching off, but after adding the fix the tests didn't pass. I am looking into other ways to fix this issue.