ambethia / recaptcha

ReCaptcha helpers for ruby apps

Home Page:http://github.com/ambethia/recaptcha

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

invisible_recaptcha_tags doesn't work with turbo_streams

sovapatr opened this issue · comments

When I submit a form in Rails 7 the respond_to format is always html and my turbo_stream.replace never runs.

It works if I make my own callback and change form.submit() to form.requestSubmit(). I'm unsure if all browsers support requestSubmit though. hotwired/turbo#775

<<-HTML
      <script>
        var invisibleRecaptchaSubmitForm = function () {
          var closestForm = function (ele) {
            var curEle = ele.parentNode;
            while (curEle.nodeName !== 'FORM' && curEle.nodeName !== 'BODY'){
              curEle = curEle.parentNode;
            }
            return curEle.nodeName === 'FORM' ? curEle : null
          };
          var el = document.querySelector(".g-recaptcha")
          if (!!el) {
            var form = closestForm(el);
            if (form) {
              form.requestSubmit();
            }
          }
        };
      </script>
HTML