2016年8月4日 星期四

[Trouble shooting][angular-ui-bootstrap] datepicker-popup focus not works after date selected

 #angular-ui   #datepicker-popup   #focus 

Problem



The datepicker-popup cannot be focused after selecting a date on version 1.3.3 .


Trouble shooting


Fix the js


Open the angular-ui-bootstrap javascript (ex. ui-bootstrap-tpls.js)

You will find there is a listener for 'uib:datepicker.focus'

// Listen for focus requests from popup directive
$scope.$on('uib:datepicker.focus', focusElement);

It will set the focus to the original directive, however it’s not works on IE. (Tested in IE11)
So we have to skip broadcasting this event when we select any date on the popup directive.

The following function will be found on controller : UibDatepickerController
Skip the last line for broadcasting, and this problem will be solved. This way was tested fine on IE11 and Chrome.

$scope.select = function(date) {
    if ($scope.datepickerMode === self.minMode) {
      var dt = ngModelCtrl.$viewValue ? dateParser.fromTimezone(new Date(ngModelCtrl.$viewValue), ngModelOptions.timezone) : new Date(0, 0, 0, 0, 0, 0, 0);
      dt.setFullYear(date.getFullYear(), date.getMonth(), date.getDate());
      dt = dateParser.toTimezone(dt, ngModelOptions.timezone);
      ngModelCtrl.$setViewValue(dt);
      ngModelCtrl.$render();
    } else {
      self.activeDate = date;
      setMode(self.modes[self.modes.indexOf($scope.datepickerMode) - 1]);

      $scope.$emit('uib:datepicker.mode');
    }

    //$scope.$broadcast('uib:datepicker.focus');  === > Don’t run this!
};






沒有留言:

張貼留言