Skip to content

Commit 22483be

Browse files
committed
fixes from victorjonsson suggestions
1 parent c7d29dd commit 22483be

File tree

2 files changed

+18
-17
lines changed

2 files changed

+18
-17
lines changed

form-validator/jquery.form-validator.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -265,8 +265,7 @@
265265
inputIsOptional = $elem.valAttr('optional') === 'true',
266266
skipBecauseDependingInputIsEmpty = false,
267267
skipBecauseItsEmpty = !value && inputIsOptional,
268-
validationRules = $elem.attr(conf.validationRuleAttribute),
269-
skipBecauseInputIsHidden = $elem.attr('disabled') || (!$elem.is(':visible') && !conf.validateHiddenInputs && (typeof validationRules !== typeof undefined && validationRules.indexOf("recaptcha") < 0)),
268+
skipBecauseInputIsHidden = $elem.attr('disabled') || (!$elem.is(':visible') && !conf.validateHiddenInputs),
270269
validationDependsOn = $elem.valAttr('depends-on') || $elem.valAttr('if-checked');
271270

272271
if (skipBecauseInputIsHidden) {
@@ -304,8 +303,10 @@
304303
return result;
305304
}
306305

306+
var validationRules = $elem.attr(conf.validationRuleAttribute),
307+
307308
// see if form element has inline err msg attribute
308-
var validationErrorMsg = true;
309+
validationErrorMsg = true;
309310

310311
if (!validationRules) {
311312
result.shouldChangeDisplay = conf.addValidClassOnAll;

src/modules/security.js

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,7 @@
516516
name: 'recaptcha',
517517
validatorFunction: function (val, $el)
518518
{
519-
return grecaptcha.getResponse($el.data('validation-recaptcha-widget-id'));
519+
return grecaptcha.getResponse($el.valAttr('recaptcha-widgetId'));
520520
},
521521
errorMessage: '',
522522
errorMessageKey: 'badreCaptcha'
@@ -529,13 +529,13 @@
529529

530530
var setupGooglereCaptcha = function (evt, $forms, config)
531531
{
532-
if( typeof grecaptcha !== typeof undefined ){
532+
if( typeof grecaptcha !== typeof undefined && !$.formUtils.hasLoadedGrecaptcha ){
533533
throw new Error('reCaptcha API can not be loaded by hand, delete reCaptcha API snippet.');
534-
}
535-
536-
var src = '//www.google.com/recaptcha/api.js?onload=reCaptchaLoaded&render=explicit' + (config.lang ? '&hl=' + config.lang : '');
537-
if ($('body').find('script[src="' + src + '"]').length === 0)
534+
} else if(!$.formUtils.hasLoadedGrecaptcha)
538535
{
536+
$.formUtils.hasLoadedGrecaptcha = true;
537+
538+
var src = '//www.google.com/recaptcha/api.js?onload=reCaptchaLoaded&render=explicit' + (config.lang ? '&hl=' + config.lang : '');
539539
var script = document.createElement('script');
540540
script.type = 'text/javascript';
541541
script.async = true;
@@ -557,29 +557,29 @@
557557
$forms.each(function ()
558558
{
559559
var $form = $(this),
560-
config = $form.context.validationConfig,
561-
theme = config.reCaptchaTheme;
560+
config = $form.context.validationConfig;
562561

563562
$('[data-validation~="recaptcha"]', $form).each(function ()
564563
{
565564
var $el = $(this),
566565
div = document.createElement('DIV'),
567-
sitekey = config.reCaptchaSiteKey || $el.valAttr('recaptcha-sitekey');
566+
siteKey = config.reCaptchaSiteKey || $el.valAttr('recaptcha-sitekey'),
567+
theme = config.reCaptchaTheme || $el.valAttr('recaptcha-theme') || 'light';
568568

569-
if( !sitekey ){
569+
if( !siteKey ){
570570
throw new Error('Google reCaptcha site key is required.');
571571
}
572572

573573
$el.hide();
574574
$el.parent().append(div);
575575

576-
var widget_id = grecaptcha.render(div, {
577-
sitekey: sitekey,
578-
theme: theme || $el.valAttr('recaptcha-theme') || 'light'
576+
var widgetId = grecaptcha.render(div, {
577+
sitekey: siteKey,
578+
theme: theme
579579
});
580580

581581
$el
582-
.data('validation-recaptcha-widget-id', widget_id);
582+
.valAttr('recaptcha-widgetId', widgetId);
583583
});
584584

585585
});

0 commit comments

Comments
 (0)