bootstrap icon indicating copy to clipboard operation
bootstrap copied to clipboard

Timepicker - some changes are not propagated immediately on blur

Open rizoom opened this issue 9 years ago • 0 comments

Bug description:

Hours, minutes and seconds field of the timepicker are bound to a blur event. In their handler functions, part of the code is wrapped into $scope.$apply but some other part are not.

Let's take an example with the minutes field. On blur, if the model was invalid and is now empty, the field will not appear valid. We will have to wait for the next digest cycle to see the change. This is illustrated with the plunker below

minutesInputEl.bind('blur', function(e) {
  ngModelCtrl.$setTouched();
  if (modelIsEmpty()) {
    // **If we use $scope.$apply here, the changes will be visible immediately.**
    makeValid();
  } else if ($scope.minutes === null) {
    invalidate(undefined, true);
  } else if (!$scope.invalidMinutes && $scope.minutes < 10) {
    $scope.$apply(function() {
      $scope.minutes = pad($scope.minutes);
    });
  }
});

Link to minimally-working plunker that reproduces the issue:

https://plnkr.co/edit/t7Kx9dziaJzY2BJ9wIys?p=preview How to reproduce the example described above:

  1. Empty the hours field, the timepicker will appear as invalid
  2. Empty the minutes field and click outside to blur the field. The timepicker still appears as invalid but should be valid.
  3. Click on the dummy force.$apply button to force a digest. The timepicker is now valid.

I have not investigated that much, so I am not sure whether or not the invalidate(undefined, true); should also be wrapped into an $apply, in which case, maybe the whole blur handler should be wrapped into one $apply.

I would be happy to submit a PR when I will have the time to investigate if you feel that a PR is needed.

Version of Angular, UIBS, and Bootstrap

Plunker based on demo page -> Angular: 1.5.8 UIBS: 2.4.0 Bootstrap: 3.3.7

rizoom avatar Jan 19 '17 10:01 rizoom