Skip to content

Commit

Permalink
fix(component): emit resolved(null) event when recaptcha expires
Browse files Browse the repository at this point in the history
fixes #11
  • Loading branch information
DethAriel committed Feb 1, 2017
1 parent a5f8a4b commit 491d99a
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions recaptcha/recaptcha.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,22 @@ export class RecaptchaComponent implements AfterViewInit, OnDestroy {

public reset() {
if (this.widget != null) {
this.grecaptcha.reset(this.widget);

if (this.grecaptcha.getResponse(this.widget)) {
// Only emit an event in case if something would actually change.
// That way we do not trigger "touching" of the control if someone does a "reset"
// on a non-resolved captcha.
this.resolved.emit(null);
}

this.grecaptcha.reset(this.widget);
}
}

/** @internal */
private expired() {
this.resolved.emit(null);
}

/** @internal */
private captchaReponseCallback(response: string) {
this.resolved.emit(response);
Expand All @@ -82,7 +87,7 @@ export class RecaptchaComponent implements AfterViewInit, OnDestroy {
this.zone.run(() => this.captchaReponseCallback(response));
},
'expired-callback': () => {
this.zone.run(() => this.reset());
this.zone.run(() => this.expired());
},
sitekey: this.siteKey,
size: this.size,
Expand Down

0 comments on commit 491d99a

Please sign in to comment.