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

Datepicker is-open issue with ng-focus #2548

Closed
Kevlys opened this issue Aug 6, 2014 · 8 comments
Closed

Datepicker is-open issue with ng-focus #2548

Kevlys opened this issue Aug 6, 2014 · 8 comments

Comments

@Kevlys
Copy link

Kevlys commented Aug 6, 2014

Hi,

When I do :

<input type="text" is-open="date_open" ng-focus="date_open = true" datepicker-popup="MM/dd/yyyy" ng-model="myDate" />

I have the following error in the console :$apply already in progress

see http://plnkr.co/edit/ZEvAW1v033aaEBFfiytF

If I use ng-click, it works.

The error seems to be caused by the line 1503 :element[0].focus();

PS : An option to (re)enable the automatic opening would be appreciate :)

@luruke
Copy link

luruke commented Aug 28, 2014

+1 for this

@filipbech
Copy link

We really need this fixed!

@alduro
Copy link

alduro commented Oct 24, 2014

This issue is solved using $timeout. This way:

     var focusElement = function() {
        $timeout(function() {
          element[0].focus();
        }, 0 , false);
      };

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

and replacing

element[0].focus(); by 
scope.$broadcast('datepicker.focus');

but the issue is that it generates a loop so the popup never closes. Looks like this was solved in 0.10.0 version.

@Fizzleban
Copy link

This is still broken in 0.12.0

@bmbell
Copy link

bmbell commented Nov 19, 2014

+1 for this

@bmbell
Copy link

bmbell commented Nov 19, 2014

The issue appears to be here:

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

This can be fixed by wrapping the focus in a timeout:

        if ( closeOnDateSelection ) {
            scope.isOpen = false;
            safeFocus();
        }

      function safeFocus() {
          $timeout(function () {
              element[0].focus();
          }, 0);
      }

@brianchance
Copy link

I am not seeing this issue with angular 1.3, but would like to +1 an option to open-on-focus (#2303)

@wesleycho
Copy link
Contributor

This issue looks fixed in master, as can be seen here.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

9 participants