Skip to content

Commit 8bd0989

Browse files
Merge pull request victorjonsson#452 from FuzzyBS/patch-1
grecaptcha validatorFunction fixed
2 parents 86900a6 + a6cd802 commit 8bd0989

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/modules/security.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,7 @@
519519
name: 'recaptcha',
520520
validatorFunction: function (val, $el)
521521
{
522-
return grecaptcha.getResponse($el.valAttr('recaptcha-widget-id'));
522+
return grecaptcha.getResponse($el.valAttr('recaptcha-widget-id')) !== '';
523523
},
524524
errorMessage: '',
525525
errorMessageKey: 'badreCaptcha'
@@ -568,9 +568,18 @@
568568
throw new Error('Google reCaptcha site key is required.');
569569
}
570570

571+
var grecaptchaRenderCallback = function(result) {
572+
$('form').each(function(){
573+
$('[data-validation~="recaptcha"]',$(this)).each(function() {
574+
$(this).trigger('validation', (result && result !== ''));
575+
});
576+
});
577+
};
571578
var widgetId = grecaptcha.render(div, {
572579
sitekey: siteKey,
573-
theme: theme
580+
theme: theme,
581+
callback: grecaptchaRenderCallback,
582+
'expired-callback': grecaptchaRenderCallback
574583
});
575584

576585
$input

0 commit comments

Comments
 (0)