Skip to content

Commit

Permalink
Update datepicker.js
Browse files Browse the repository at this point in the history
Fix for issue angular-ui#2789 where it was throwing "$apply already in progress" when using ng-focus to open the popup.
  • Loading branch information
pedroxs committed Oct 16, 2014
1 parent b9db670 commit 31e283d
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/datepicker/datepicker.js
Original file line number Diff line number Diff line change
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

2 comments on commit 31e283d

@OlmoAcerta
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@FDiskas
Copy link

@FDiskas FDiskas commented on 31e283d Jan 5, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing $timeout

ReferenceError: $timeout is not defined

Please sign in to comment.