Skip to content

Commit

Permalink
Trigger HTMl validation before recaptcha submit
Browse files Browse the repository at this point in the history
  • Loading branch information
rebecca-shoptaw committed May 13, 2024
1 parent 0f021a2 commit 732820a
Showing 1 changed file with 7 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
export function initRealTimeValidation() {
const i18nStrings = JSON.parse(document.querySelector('form[name="signup"]').dataset.i18n);
const signupForm = document.querySelector('form[name=signup]');
const i18nStrings = JSON.parse(signupForm.dataset.i18n);

if (window.grecaptcha) {
// Callback that is called when grecaptcha.execute() is successful
function submitCreateAccountForm() {
const signupForm = document.querySelector('form[name=signup]')
signupForm.submit()
}
window.submitCreateAccountForm = submitCreateAccountForm
Expand Down Expand Up @@ -96,8 +96,10 @@ export function initRealTimeValidation() {

$('#signup').on('click', function(e) {
e.preventDefault();
if (window.grecaptcha) {
window.grecaptcha.execute()
}
if (signupForm.checkValidity()) {
if (window.grecaptcha) {
window.grecaptcha.execute()
}
} else signupForm.reportValidity();
});
}

0 comments on commit 732820a

Please sign in to comment.