From 1d3953467fc5dc03313f004dd7cb420fba09c473 Mon Sep 17 00:00:00 2001 From: Evan Sharp Date: Mon, 8 Feb 2016 14:56:06 -0500 Subject: [PATCH] Reset directive when reCaptcha is reset Resolves #69 and #111. When the service triggers a reset, the directive associated with the widgetid being reset will clear the response on the model and mark the element as invalid (if validation is enabled). --- src/directive.js | 7 +++++++ src/service.js | 6 +++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/directive.js b/src/directive.js index c525b2a..0ac2aa1 100644 --- a/src/directive.js +++ b/src/directive.js @@ -60,6 +60,13 @@ scope.$on('$destroy', destroy); + scope.$on('reCaptchaReset', function(resetWidgetId){ + if(widgetId === resetWidgetId){ + scope.response = ""; + validate(); + } + }) + }); // Remove this listener to avoid creating the widget more than once. diff --git a/src/service.js b/src/service.js index 211c0cc..7aeadc8 100644 --- a/src/service.js +++ b/src/service.js @@ -86,7 +86,7 @@ provider.onLoadFunctionName = onLoadFunctionName; }; - provider.$get = ['$window', '$q', function ($window, $q) { + provider.$get = ['$rootScope','$window', '$q', function ($rootScope, $window, $q) { var deferred = $q.defer(), promise = deferred.promise, recaptcha; $window.vcRecaptchaApiLoadedCallback = $window.vcRecaptchaApiLoadedCallback || []; @@ -160,8 +160,8 @@ // $log.info('Reloading captcha'); recaptcha.reset(widgetId); - // reCaptcha will call the same callback provided to the - // create function once this new captcha is resolved. + // Let everyone know this widget has been reset. + $rootScope.$broadcast('reCaptchaReset', widgetId); }, /**