Skip to content
This repository was archived by the owner on Aug 17, 2021. It is now read-only.

Commit 1d39534

Browse files
author
Evan Sharp
committed
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).
1 parent a15c614 commit 1d39534

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

src/directive.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,13 @@
6060

6161
scope.$on('$destroy', destroy);
6262

63+
scope.$on('reCaptchaReset', function(resetWidgetId){
64+
if(widgetId === resetWidgetId){
65+
scope.response = "";
66+
validate();
67+
}
68+
})
69+
6370
});
6471

6572
// Remove this listener to avoid creating the widget more than once.

src/service.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@
8686
provider.onLoadFunctionName = onLoadFunctionName;
8787
};
8888

89-
provider.$get = ['$window', '$q', function ($window, $q) {
89+
provider.$get = ['$rootScope','$window', '$q', function ($rootScope, $window, $q) {
9090
var deferred = $q.defer(), promise = deferred.promise, recaptcha;
9191

9292
$window.vcRecaptchaApiLoadedCallback = $window.vcRecaptchaApiLoadedCallback || [];
@@ -160,8 +160,8 @@
160160
// $log.info('Reloading captcha');
161161
recaptcha.reset(widgetId);
162162

163-
// reCaptcha will call the same callback provided to the
164-
// create function once this new captcha is resolved.
163+
// Let everyone know this widget has been reset.
164+
$rootScope.$broadcast('reCaptchaReset', widgetId);
165165
},
166166

167167
/**

0 commit comments

Comments
 (0)