bootstrap icon indicating copy to clipboard operation
bootstrap copied to clipboard

Datepicker is-open issue with ng-focus

Open Kevlys opened this issue 12 years ago • 8 comments

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 :)

Kevlys avatar Aug 06 '14 08:08 Kevlys

+1 for this

luruke avatar Aug 28 '14 15:08 luruke

We really need this fixed!

filipbech avatar Sep 11 '14 09:09 filipbech

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.

alduro avatar Oct 24 '14 20:10 alduro

This is still broken in 0.12.0

Fizzleban avatar Nov 19 '14 11:11 Fizzleban

+1 for this

bmbell avatar Nov 19 '14 11:11 bmbell

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);
      }

bmbell avatar Nov 19 '14 12:11 bmbell

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

brianchance avatar Nov 21 '14 16:11 brianchance

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

wesleycho avatar Aug 08 '15 06:08 wesleycho