<?xml version="1.0" encoding="UTF-8"?>
<root>
    <default>
        <includes>
            <!--
                Path to css and js files into plugins folder.
                If your files are not in plugins folder, use absolute paths.
            -->
            <css>
            </css>
            <js>
                <file>https://www.google.com/recaptcha/api.js?render=%sitekey%</file>
            </js>
        </includes>
        <js_code>
<![CDATA[   grecaptcha.ready(function() {
        var $submitBtn = $("%selector%").find('button[type="submit"]');
        if($submitBtn[0]) {
            $('input[name="%response_fieldname%"]').val('');
            if($("%selector%").hasClass('has-validator')) {
                // if formvalidation enabled

                var formId = $("%selector%").attr('id');
                var form   = forms[formId];

                $('%selector%').addClass('has-recaptcha-v3')

                $submitBtn.on('click', function(e) {
                    e.preventDefault;
                    form.fv.validate()
                    .then (function(status) {
                        if (status == 'Valid') {
                            grecaptcha.execute('%sitekey%', {action: '%action%'}).then(function(token) {
                                $('input[name="%response_fieldname%"]').val(token);
                                $("%selector%").submit();
                            });
                        }
                        return false;
                    });
                    return false;
                });
            } else {
                $submitBtn.on('click', function(e) {
                    e.preventDefault;
                    grecaptcha.execute('%sitekey%', {action: '%action%'}).then(function(token) {
                        $('input[name="%response_fieldname%"]').val(token);
                        $("%selector%").submit();
                    });
                    return false;
                });
            }
        } else {
            $("%selector%").prepend('<p class="alert alert-danger">Recaptcha V3 - no submit button found</p>');
        }
    });
]]>
        </js_code>
    </default>
</root>
