I use the new reCaptcha with the jQuery Validate plugin. The validation plugin works nice with my form but unfortunately it didn't work with reCaptcha. My attempt to make it work below:
HTML:
<div class="g-recaptcha" name="recaptcha" id="recaptcha" data-sitekey="XXXXX"></div>
Javascript:
recaptcha: {
required: true
}
but it didn't worked. Does anyone know how to fix this. I simply need the default This field is required error message.
Your code:
with...
You cannot validate a
<div>
. Period.The jQuery Validate plugin can only validate
<input>
,<textarea>
and<select>
elements that are also within a<form></form>
container.The only workaround would be to copy your value into a
type="hidden"
input
element and then apply your validation to that.You should add hidden input for reCaptcha, cause jQuery Validation can only validate input/textarea/select:
Then rewrite your JS like this:
That's all.
hoping that you are using HTML5 form tag.
simply use required in the end
So I managed to make it worked. The only problem is after user completing reCaptcha, the message This field is required does not quickly dissapear. I'm using blur, keydown and focusout to detect user input and remove the error message.
JS:
HTML: