What is the best way to implement multiple reCaptcha in a single component in vue.js?

I am facing an issue with adding reCaptcha to 2 tabs within a component. The code I implemented only displays the captcha in the first tab.

<div class="tab-content clearfix">
 <div class="tab-pane active" id="1a">
  <form>
   <div class="g-recaptcha" id="recaptchaTab1" :data-sitekey="rcapt_sig_key"></div>
  </form>
 </div>  
</div>  
<div class="tab-content clearfix">
 <div class="tab-pane active" id="1a">
  <form>
   <div class="g-recaptcha" id="recaptchaTab2" :data-sitekey="rcapt_sig_key"></div>
  </form>
 </div>  
</div>

In javascript

data() {
 return {
  rcapt_sig_key: "site_key",
  recaptchaTab2: 0,
  recaptchaTab1: 0
  }
},
mounted() {
  if (window.grecaptcha) {
   this.rcaptIdTab2 = grecaptcha.render( 'recaptchaTab2', { sitekey : this.rcapt_sig_key });
   this.rcaptIdTab1 = grecaptcha.render( 'recaptchaTab1', { sitekey : this.rcapt_sig_key });
  }
 }

Upon refreshing the page, the captcha is still only displayed in the first tab.

Answer №1

The reason for this issue is the functionality of ReCaptcha, which does not allow multiple instances to be rendered on a single page, as you are currently attempting in your component. (https://groups.google.com/forum/#!topic/recaptcha/kOYcRJCSDXM).

You have a few options to resolve this - either share the same ReCaptcha instance among all forms on the page, use popups to display the ReCaptcha, or try offloading the rendering and parsing to the server with some AJAX.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What is the best way to repair all the data or preserve it using my current theme?

Seeking assistance here. I am new to developing themes and have a query. Let's say, I have developed a theme myself. Now my question is, after creating menus, posts, pages, etc., when I install just the theme on another WordPress site, all the data ge ...

Error: Unable to locate App.js file upon transition to Typescript

I'm in a bit of a bind with my Laravel project and I'm struggling to find a solution. I recently tried to upgrade from vue2 to vue3 with typescript, following this tutorial for the vue upgrade and this tutorial for typescript integration. However ...

send css as a parameter to the component

Could it be possible to develop a component with specific CSS attributes? I am aware that the following approach is not valid. <template> <div id="textContainer"> {{ content }} </div> </template> <script> export defa ...

Challenges encountered while attempting to install npm in a Vue.js project

Encountered several errors like the ones below: npm ERR! code ERR_SOCKET_TIMEOUT npm ERR! network Socket timeout npm ERR! network This is a problem related to network connectivity. npm ERR! network In most cases you are behind a proxy or have bad network s ...

Initiate an AJAX call

Hey there, I have a piece of code that I need some help with. <button onclick="sbt()" name="step1[save]" type="submit" class="btn-type5 next-btn-form pie" value="Далее">Send</button> function sbt(){ var phone = document.getElementById(&ap ...

Begin and execute an external function upon clicking the button

Is there a way to incorporate a plugin after clicking on a button? The following code does not work on document ready. $(document).ready(function() { $("#activate").click(function() { var script = document.createElement('script&apos ...

Combining queries in mongodb with nested joins

I'm attempting to retrieve a structure where I first populate content, and within content there is an array field named comments. From comments, I aim to populate user. Below is the schema: const contentScheme = new Schema({ post_id: { type: Num ...

How is it possible for JavaScript functions to be accessed prior to being defined?

Similar Question: Why can I access a function before it's declared in JavaScript? Unexpectedly, the following code results in an error due to the undefined Foo: window.Foo = Foo; This code snippet also triggers the same error: window.Foo = Foo ...

The issue of the selection option not being cleared after being set to 0 persists in JavaScript

I am facing an issue where I need to reset the select option to `0` when another option is selected. I have tried the code below for this purpose. if (varALPO1MobNum == "0") { var selectElement = $(&apo ...

Adjusting the alignment of Bootstrap navbar items upon clicking the toggle button

When I click the toggle button on a small screen, my navbar items appear below the search bar instead of aligning with the home and about elements. Below is an image depicting this issue: https://i.stack.imgur.com/4rabW.png Below is the HTML code structu ...

Challenges with the Parent Element in jQuery appendTo Operation

First of all, I want to express my gratitude for your help in advance. My goal is to place a hovering div on top of every anchor tag present on a webpage. I aim to calculate the offset, height, and width of each element, then create a new div with CSS set ...

Ensure that only one input is required to be filled in with Vuelidate's requiredUnless validation rule

Within my Vuelidate validation setup, I am dealing with three input fields namely jobApplyEmail, jobApplyPhone, and jobApplyOther. It is mandatory for users to provide at least one input among these three. To enforce this requirement, I have implemented th ...

The Material-ui Select component is experiencing issues with updating the state accurately

When creating a multiple select input using Material-UI, I encountered an issue with setting the default selected values from state. Despite having an array of two objects in the state and setting it as the select value, the default objects are not being ...

Tips for positioning bootstrap-vue dropdown button items evenly

Can anyone help me align the dropdown button child items horizontally? I've tried customizing it with CSS but no luck. The control link can be found here Check out a sample on Js Fiddle here This is how I expect the design to look like: https://i.s ...

`Are you incorporating Material UI tabs with React Router in your project?`

Looking for help with a project utilizing react/typescript. Here's the react router configuration: const Root = () => ( <> <NavBar/> <Router> <Route path="/" component={Home} /> <Route ...

Setting the width of individual Views within a ScrollView to adjust accordingly in React Native

Is there a way to ensure that the Views inside my horizontal ScrollView have the same dimensions as the ScrollView itself? I'd like to implement paging so that swiping takes me to the next View within the ScrollView. I attempted using width : "100%" b ...

Stopping JavaScript when scrolling to the top and running it only when not at the top

I found a great jQuery plugin for rotating quotes: http://tympanus.net/codrops/2013/03/29/quotes-rotator/ Check out this JSFiddle example: http://jsfiddle.net/LmuR7/ Here are my custom settings (with additional options that I haven't figured out yet) ...

Having difficulty accessing certain code in TypeScript TS

Struggling with a TypeScript if else code that is causing errors when trying to access it. The specific error message being displayed is: "Cannot read properties of undefined (reading 'setNewsProvider')" Code Snippet if (this.newsShow != ...

The behavior of Angular 4 CSS and JS changes upon refreshing the page

Every time I try to load a page with this particular script: this.router.navigateByUrl('/report-result/'+report.id); It appears that not all the CSS and JS files are being loaded properly. The bootstrap popovers don't show up, and some ele ...

Could anyone assist me in positioning my personalized Context Menu beside my cursor?

If possible, I would appreciate some assistance with my custom context menu. It may require some minor tweaks or a fresh idea on how to address the issue. Ideally, I would like to keep the HTML and CSS somewhat unchanged. [I'm not sure what to write ...