diff --git a/README.md b/README.md
index 20e6cf8..ddaf99a 100644
--- a/README.md
+++ b/README.md
@@ -427,7 +427,8 @@ but only accepts the following options:
| `:script` | Same as setting both `:inline_script` and `:external_script`. (default: `true`). |
| `:inline_script` | If `true`, adds an inline script tag that calls `grecaptcha.execute` for the given `site_key` and `action` and calls the `callback` with the resulting response token. Pass `false` if you want to handle calling `grecaptcha.execute` yourself. (default: `true`) |
| `:element` | The element to render, if any (default: `:input`) `:input`: Renders a hidden `` tag. The value of this will be set to the response token by the default `setInputWithRecaptchaResponseTokenFor{action}` callback. `false`: Doesn't render any tag. You'll have to add a custom callback that does something with the token. |
-| `:turbolinks` | If `true`, calls the js function which executes reCAPTCHA after all the dependencies have been loaded. This cannot be used with the js param `:onload`. This makes reCAPTCHAv3 usable with turbolinks. |
+| `:turbo` | If `true`, calls the js function which executes reCAPTCHA after all the dependencies have been loaded. This cannot be used with the js param `:onload`. This makes reCAPTCHAv3 usable with turbo. |
+| `:turbolinks` | Alias of `:turbo`. Will be deprecated soon. |
| `:ignore_no_element` | If `true`, adds null element checker for forms that can be removed from the page by javascript like modals with forms. (default: true) |
[JavaScript resource (api.js) parameters](https://developers.google.com/recaptcha/docs/invisible#js_param):
diff --git a/lib/recaptcha/helpers.rb b/lib/recaptcha/helpers.rb
index 09b77fc..85d2cdc 100644
--- a/lib/recaptcha/helpers.rb
+++ b/lib/recaptcha/helpers.rb
@@ -12,7 +12,7 @@ def self.recaptcha_v3(options = {})
action = options.delete(:action) || raise(Recaptcha::RecaptchaError, 'action is required')
id = options.delete(:id) || "g-recaptcha-response-data-#{dasherize_action(action)}"
name = options.delete(:name) || "g-recaptcha-response-data[#{action}]"
- turbolinks = options.delete(:turbolinks)
+ turbo = options.delete(:turbo) || options.delete(:turbolinks)
options[:render] = site_key
options[:script_async] ||= false
options[:script_defer] ||= false
@@ -24,11 +24,11 @@ def self.recaptcha_v3(options = {})
end
options[:class] = "g-recaptcha-response #{options[:class]}"
- if turbolinks
+ if turbo
options[:onload] = recaptcha_v3_execute_function_name(action)
end
html, tag_attributes = components(options)
- if turbolinks
+ if turbo
html << recaptcha_v3_onload_script(site_key, action, callback, id, options)
elsif recaptcha_v3_inline_script?(options)
html << recaptcha_v3_inline_script(site_key, action, callback, id, options)
diff --git a/test/client_helper_test.rb b/test/client_helper_test.rb
index ee2345a..23eb5fa 100644
--- a/test/client_helper_test.rb
+++ b/test/client_helper_test.rb
@@ -90,6 +90,19 @@
html.must_include("onload=executeRecaptchaForRequest")
end
end
+
+ describe "turbo" do
+ it "adds onload to defined function" do
+ html = recaptcha_v3(action: 'request', turbo: true)
+ html.must_include("onload=executeRecaptchaForRequest")
+ end
+
+ it "overrides specified onload" do
+ html = recaptcha_v3(action: 'request', onload: "foobar", turbo: true)
+ html.wont_include("onload=foobar")
+ html.must_include("onload=executeRecaptchaForRequest")
+ end
+ end
it "adds :render option to the url" do
html = recaptcha_tags(render: 'onload')