D
D
denism3002019-03-23 10:20:15
JavaScript
denism300, 2019-03-23 10:20:15

How to reset reCaptcha after closing modal window?

There is a function to call reCaptcha

var initRec;
function initRecaptcha(modal) {
    var captcha = modal.find(".g-recaptcha");
    initRec = grecaptcha.render(captcha.attr("id"), {
        "sitekey" : "SITE_KEY",
        "callback" : function(token) {
            captcha.parent().find(".g-recaptcha-response").val(token);
            captcha.parent().submit();
        }
    });
}

when a modal window is called, it is initialized, I also wrote reCaptcha reset when the window is closed
$('.usluga1_btn').click(function() {
    $('.usluga1_popup').bPopup({
        onOpen: function() {
            initRecaptcha($(this));
        },
        onClose: function() {
            grecaptcha.reset(initRec);
        }			
    });
});

however, if you open the window, close it and try to open it again, then the error in the console is
Uncaught Error: reCAPTCHA has already been rendered in this element

i.e., reCAPTCHA did not reset. How to fix?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question