Issues arise in the alignment of the tab order when utilizing a combination of the stripe card

Experiencing an issue with tab index not working properly when using Vue.js and having a stripe card-element inside the Vue main element. Below is the code snippet:

<html>
<head>
    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
    <script src="https://js.stripe.com/v3/"></script>
</head>
<body>
    <input type="text" placeholder="first tab element on page"><br />
    <br />
    <div id="stripeDiv">
        <div id="card-element" style="border: 1px solid black;max-width:300px">
            <!-- A Stripe Element will be inserted here. -->
        </div>
        <div id="card-errors" role="alert"></div>
    </div>    
    <br />
    <input type="text" placeholder="tab element after stripe form"><br />
    <script>
        var stripe = Stripe("somestripepublickey");
        var card = stripe.elements().create('card').mount('#card-element');

        var vue_test = new Vue({
            el: '#stripeDiv'
        });
    </script>
</body>
</html>

Upon tabbing through, the focus shifts to the top input box right after exiting the stripe fields instead of the intended bottom input box.

One possible solution is to use JavaScript with onfocus, although alternative approaches are preferred.

Note: Testing can be done without requiring a Stripe account.

Answer №1

To resolve the issue, simply rearrange the order of your JavaScript code. When mounting the card element, it triggers various activities on the DOM.

var stripe = Stripe("somestripepublickey");
var vue_test = new Vue({
  el: '#stripeDiv'
});
var card = stripe.elements().create('card').mount('#card-element');

Following this sequence should address your problem effectively.

Answer №2

Although I don't currently use Vue in my projects, I encountered a similar issue that may be relevant to your situation. I discovered that the problem stemmed from attempting to mount the #card-element before the DOM was fully loaded. To resolve this, I wrapped the code in a function that waits for the DOM to be completely loaded before initializing the necessary Stripe components. Here's a snippet of what worked for me:

document.addEventListener('DOMContentLoaded', function() {
    var stripe = Stripe("myStripeKey");
    var card = stripe.elements().create('card').mount('#card-element');

    var vueInstance = new Vue({
        el: '#stripeDiv'
    });
});

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

Locating the chosen value from a dropdown within a div: A step-by-step

Code Viewer: <div id="maindiv"> for(i=1;i<3;i++) { <div id="subdiv"> @html.dropdownlistfor(m=>m.id,new selectlist((viewbag.country) as selectlist,"Value","Text"),new{@class="country"}) ...

Comparison of jQuery, AngularJS, and Node.js

I'm a beginner in web development and I have some basic knowledge: HTML - structure of websites CSS - design aspect JavaScript - for adding interactivity Now, what exactly is jQuery, AngularJS, and Node.js? Upon researching, I discovered that jQue ...

The function exclusively examines the final element within the array

When validating user-submitted emails in my function, I compare each email to a list of valid email domains. The user emails are stored in an array, as well as the valid email domains. However, the issue arises when using the function as it only checks if ...

Adjust the size of an element in response to changes in the size of

I've implemented a jQuery function to resize an element dynamically based on window size changes: $(window).resize(function() { topHeight = $("#top").height(); height = $(window).height() - 210; $("#container").height(height); $("#g").height( ...

Create a dynamic slideshow using a bootstrap carousel in conjunction with the powerful php glob() function

I'm struggling to create a homepage featuring a slider that pulls images dynamically from a subfolder within the Wordpress uploads directory. Here's my code: <div id="" class="carousel slide" data-ride="carousel"> <!-- Wrapper for sl ...

It appears that the JavaScript global dynamic variable is undefined as it changes from function to function, suggesting it might be

I'm encountering an issue with the way these two functions interact when used in onclick calls of elements. Due to external circumstances beyond my control, I need to keep track of when and how elements are hidden. Everything works perfectly as inten ...

What is the best way to divide an array into pairs and store them in separate arrays?

I'm attempting to challenge my JavaScript skills and faced with a dilemma. There is an array containing data var array = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];. The goal is to pair the elements and generate a new array of arrays such as var newArray = [[1 ...

Ensuring that a canvas remains centered and completely visible within its parent element while zooming in React

Currently, I am developing a straightforward PowerPoint creator using React. In this project, I have integrated a zoom feature for a canvas element. The principle is that the canvas should resize based on a scale factor. However, there seems to be an issue ...

Utilizing Vue.js to add functionality for navigation buttons allowing users to move between survey questions

In my Vue.js component, I've written code to show survey questions in a mobile app for users. Here is a snippet of the code: <div class="col-12 p-0" v-for="( i, index ) in questions" :key="i"> <p cl ...

Do I need to include the title, html, and head tags in a page that is being requested via ajax

I have a page called welcome.htm that is being loaded into another page using ajax. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xh ...

When forcibly closing a window, the disconnect event for Socket.IO sockets may not trigger as expected

Currently in the process of creating chat rooms with Socket.io. I've had good success so far, as it's user-friendly and well-documented. However, I've noticed that if I reload the page, wait for the socket to connect, and then close the w ...

Is there a way to determine the number of options required for a select tag to become scrollable?

Please review these two <select> elements: <select> <option>one</option> <option>one</option> <option>one</option> <option>one</option> <option>one</option> <option&g ...

Run a JavaScript function once the one before it has finished executing

I need help with executing a series of JavaScript functions in a specific order, where each function must wait for the previous one to complete. I've tried multiple approaches but haven't been successful so far. Any suggestions would be greatly a ...

Implementing the SendOwl License API for theme licensing

Currently developing a Shopify theme for sale and exploring licensing options Considering using SendOwl's API for licenses - Shopify themes support html/css/js/liquid, no server-side code, so JavaScript is required. Can the SendOwl API be used to v ...

Can new content be incorporated into an existing JSON file using HTML input and the fs.writeFile function?

I recently started learning about node.js and decided to create a comment section that is rendered by the node.js server. I successfully passed the value from a json file into an ejs file, which rendered fine. Now, I have added an input field and submit b ...

I'm struggling to understand how to properly utilize the "path" parameter in the app.use() function. The outcome it produces is not what I had anticipated

I am a beginner in express.js and I have been trying to understand how to properly use "path" in the app.use() function. However, when I execute the code as shown below, the result is not what I anticipated and it's quite confusing for me. Can you ple ...

Transferring data from a child component to a parent component

In my Nuxt UI component, I have the following code: <template> <div> <label for="phone" class="block mb-2 text-sm font-medium text-gray-900 dark:text-gray-300">{{ $t('nav.cellphone') }}</la ...

What is the best approach to transforming my jQuery function into CSS to ensure responsiveness?

I have created a jQuery animation with four functions named ani1(), ani2(), ani3(), and ani4(). Everything is working fine on desktop, but now I am facing the challenge of making it responsive for mobile devices. I am looking for CSS code to replicate the ...

What is the best way to create a mapping function in JavaScript/TypeScript that accepts multiple dynamic variables as parameters?

Explaining my current situation might be a bit challenging. Essentially, I'm utilizing AWS Dynamodb to execute queries and aiming to present them in a chart using NGX-Charts in Angular4. The data that needs to appear in the chart should follow this fo ...

I am having trouble retrieving the $post variable in PHP when posting a Vue.js form

I am currently working on a Vue.js form that features dynamic rows. To capture and process the results in a PHP page, I have utilized a traditional HTML form tag. However, the output in my PHP page does not display the $post data as expected. You can view ...