Skip to content
This repository has been archived by the owner on May 29, 2019. It is now read-only.

Fix for issue #2789 "$apply already in progress" when using ng-focus to open the popup. #2845

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions src/datepicker/datepicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -430,8 +430,8 @@ angular.module('ui.bootstrap.datepicker', ['ui.bootstrap.dateparser', 'ui.bootst
showButtonBar: true
})

.directive('datepickerPopup', ['$compile', '$parse', '$document', '$position', 'dateFilter', 'dateParser', 'datepickerPopupConfig',
function ($compile, $parse, $document, $position, dateFilter, dateParser, datepickerPopupConfig) {
.directive('datepickerPopup', ['$compile', '$parse', '$document', '$position', '$timeout', 'dateFilter', 'dateParser', 'datepickerPopupConfig',
function ($compile, $parse, $document, $position, $timeout, dateFilter, dateParser, datepickerPopupConfig) {
return {
restrict: 'EA',
require: 'ngModel',
Expand Down Expand Up @@ -524,6 +524,13 @@ function ($compile, $parse, $document, $position, dateFilter, dateParser, datepi
}
ngModel.$parsers.unshift(parseDate);

function closeWithFocus() {
$timeout(function () {
scope.isOpen = false;
element[0].focus();
}, 0, false);
}

// Inner change
scope.dateSelection = function(dt) {
if (angular.isDefined(dt)) {
Expand All @@ -533,8 +540,7 @@ function ($compile, $parse, $document, $position, dateFilter, dateParser, datepi
ngModel.$render();

if ( closeOnDateSelection ) {
scope.isOpen = false;
element[0].focus();
closeWithFocus();
}
};

Expand Down Expand Up @@ -600,8 +606,7 @@ function ($compile, $parse, $document, $position, dateFilter, dateParser, datepi
};

scope.close = function() {
scope.isOpen = false;
element[0].focus();
closeWithFocus();
};

var $popup = $compile(popupEl)(scope);
Expand Down