Skip to content

invisible_recaptcha_tags doesn't work with turbo_streams #423

@sovapatr

Description

@sovapatr

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions