LP#1670512 Apply focus/select model udpates via timeout
authorBill Erickson <berickxx@gmail.com>
Tue, 7 Mar 2017 17:25:32 +0000 (12:25 -0500)
committerKathy Lussier <klussier@masslnc.org>
Tue, 21 Mar 2017 13:48:12 +0000 (09:48 -0400)
Avoid manually invoking scope.$apply() in the midst of an angular
$digest loop, since this is forbidden by angular.  Wrap the apply()'s in
a $timeout, so they occur after the currently running digest.

Fixes the focusMe, blurMe, and selectMe directives.

Signed-off-by: Bill Erickson <berickxx@gmail.com>
Signed-off-by: Kathy Lussier <klussier@masslnc.org>
Open-ILS/web/js/ui/default/staff/services/ui.js

index 5d73487..7328e7d 100644 (file)
@@ -19,7 +19,9 @@ function($timeout , $parse) {
                     $timeout(function() {element[0].focus()});
             });
             element.bind('blur', function() {
-                scope.$apply(model.assign(scope, false));
+                $timeout(function() {
+                    scope.$apply(model.assign(scope, false));
+                });
             })
         }
     };
@@ -41,7 +43,9 @@ function($timeout , $parse) {
                     $timeout(function() {element[0].blur()});
             });
             element.bind('focus', function() {
-                scope.$apply(model.assign(scope, false));
+                $timeout(function() {
+                    scope.$apply(model.assign(scope, false));
+                });
             })
         }
     };
@@ -61,7 +65,9 @@ function($timeout , $parse) {
                     $timeout(function() {element[0].select()});
             });
             element.bind('blur', function() {
-                scope.$apply(model.assign(scope, false));
+                $timeout(function() {
+                    scope.$apply(model.assign(scope, false));
+                });
             })
         }
     };