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

Commit

Permalink
Reset directive when reCaptcha is reset
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
Evan Sharp committed Feb 18, 2016
1 parent a15c614 commit 1d39534
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
7 changes: 7 additions & 0 deletions src/directive.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 3 additions & 3 deletions src/service.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 || [];
Expand Down Expand Up @@ -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);
},

/**
Expand Down

0 comments on commit 1d39534

Please sign in to comment.