Guide on attaching custom functions to Vuetify stepper's previous and next buttons

I'm in the process of setting up a login flow using Vuetify. The idea is that in the first step, users enter their email address, in the second step they provide their password, and in the third step, they input TOTP information for a 2nd-factor authentication check.

After each step, I want to execute a custom function that sends a request to the server and only proceeds to the next step if a valid response is received.

(Step 1: verifying email existence, Step 2: confirming correct password, Step 3: validating the TOTP token)

However, I'm facing an issue where my custom functions are not being attached to the stepper action buttons.

Below is a stripped-down version of my code:

<template>
  <v-container>
    <v-card>
      <v-stepper
        v-model="step"
        :items="items"
        @click:prev="prev"
        @click:next="next"
      >
        <template v-slot:item.1>
        </template>
        <template v-slot:item.2>
        </template>
        <template v-slot:item.3>
        </template>
      </v-stepper>
    </v-card>
  </v-container>
</template>

<script setup lang="ts">
import { ref } from 'vue';

const step = ref(0);

const items = [
  { title: 'E-Mail' },
  { title: 'Password' },
  { title: '2nd-Factor' },
];

const prev = () => {
  console.log('clicked prev')
  
  # move to previous step
}
const next = () => {
  console.log('clicked next')

  # make background call

  if(# error) {
    # handle error
  }

  # proceed to next step on success
}
</script>

<style scoped lang="sass">

</style>

Even though I have defined the prev and next functions, they do not work when clicking the buttons within the stepper action menu.

It's worth noting that I opted for TypeScript over plain JavaScript in this implementation.

Answer №1

Refer to the documentation shared by @yoduh above, and implement something similar to this:

Template

<v-stepper-actions
      :disabled="disabled"
      @click:next="customNext(next)"
      @click:prev="prev"
    ></v-stepper-actions>

JavaScript

methods: {
  customNext(next) {
    alert('custom next function')
    console.log('custom next function')
    next()
  },
},

View this example

Answer №2

To implement v-model step with a custom action, follow this example:

`<v-stepper :items="items" v-model="step" hide-actions >
  <template v-slot:item.1 >
   foo
  </template>

    <template v-slot:item.2>
      <v-card title="Step Two" flat>...</v-card>
    </template>

    <template v-slot:item.3>
      <v-card title="Step Three" flat>...</v-card>
    </template>

      <v-stepper-actions
          :disabled="false"
          :next-text="step>1?'finish':'next'"
          :prev-text="step>1?'back':''"
          @click:next="step=step+1"
          @click:prev="step=step-1"
        ></v-stepper-actions>
  </v-stepper>
<script setup>
let step = ref(1);
const items=ref(['test1', 'head2', 'foo3'])
</script>
`

It's possible that you won't need any additional functions for next steps and actions.

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

NestJS Resolver Problem: Getting an Undefined Error

Could use a bit of assistance. I'm currently working on a mutation and encountering the following error: ERROR [ExceptionsHandler] Cannot read properties of undefined (reading 'entryUser') Here is the resolver code snippet: export class Us ...

Error 404: Unable to locate bootstrap in app.js using Laravel 10 and Vite

I'm currently developing my app using Laravel 10 with Vite. However, I encountered an issue when trying to build and load Vite within my Blade template using the following code snippet: @vite('resources/js/app.js') Upon doing so, I received ...

Modifying a property in a nested layout through a page in Next.js 13

Currently, I am facing a challenge in updating the page title within a nested layout structure. app/docs/layout.tsx: export const DocsLayout = ({children}:{children: React.ReactNode}) => { return ( <> <header> ...

Troubleshooting `TypeError: document.createRange is not a function` error when testing material ui popper using react-testing-library

I am currently working with a material-ui TextField that triggers the opening of a Popper when focused. My challenge now is to test this particular interaction using react-testing-library. Component: import ClickAwayListener from '@material-ui/core/ ...

Unleashing the Power of v-model in Vue.js: A Comprehensive Guide to Referencing Input

I am a beginner in vue.js and I am currently facing an issue with making a get request from a field that has a v-model="embed.url" after pasting a link. The paste event works fine, but I'm struggling to reference the input with v-model="embed.url" and ...

TS2304: The build process is unable to locate the name 'iterable' within @types

As an experienced dog attempting to master new tricks like npm and TypeScript, I find myself faced with a challenge in my Visual Studio 2017 project. Despite setting it to "Latest" TypeScript 2.5 and adding @types/jquery (3.2.12), the project keeps throwin ...

Deactivate the FormGroup by implementing Validators

In my form, I have a checkbox group named formArray within my checkboxForm. The task at hand is to disable the submit button if none of the checkboxes are checked. To achieve this, I created a custom validator for my checkboxForm and here is my approach: ...

Implementing undefined value acceptance in yup object when using Material-UI

Even though I have clearly specified that the key is optional in my Form, for some reason my input does not accept undefined as a value. Instead, I keep getting this error message: bonusPercentage must be a number type, but the final value was: NaN (cast ...

NextJS middleware API receives an uploaded image file form, but the request is undefined

Currently, I'm utilizing NextJS to handle form data processing and database uploads, with a pit stop at the NextJS API middleware for image editing. pages/uploadImage.tsx This is the client-side code handler. ... async function handleImageUpload(imag ...

EventListener cannot be removed

My TypeScript class is structured like this: class MyClass { let canvas: any; constructor(canvas: any) { this.canvas = canvas; this.canvas.requestPointerLock = this.canvas.requestPointerLock; document.exitPointerLock = ...

Invoke a method within a function triggered by the .call() method

Currently, I am developing an n8n node that essentially functions every time a specific event occurs. To facilitate this process, I have created an abstract class which is invoked by the n8n environment. However, there seems to be a limitation in calling ...

Customizing MUI DataGrid: Implementing unique event listeners like `rowDragStart` or `rowDragOver`

Looking to enhance MUI DataGrid's functionality by adding custom event listeners like rowDragStart or rowDragOver? Unfortunately, DataGrid doesn't have predefined props for these specific events. To learn more, check out the official documentati ...

SweetConfirm: The Perfect Combination of Vue and Laravel

I am attempting to delete my data after confirmation, and I would like to utilize sweetalert for this purpose. 1 If I use a simple alert like: deletePage(index) { if (confirm("Do you really want to delete it?")) { let page = this.pages[index]; axio ...

What is preventing me from accessing the additional JavaScript functions in Vue Laravel?

After stumbling upon a code snippet online that utilized a class without specifying whether it was for Vue or JavaScript, I decided to test it out. However, I encountered an issue where I couldn't access any functions after importing the class. I bel ...

Guide to separating the bytes of a number and placing them into an Uint8Array

I am looking to convert a JavaScript number into the smallest possible uint8array representation. For example : 65 535 = Uint8Array<[255,255]> (0b1111111111111111 = [0b11111111, 0b11111111]) 12 356 = Uint8Array<[48,68]> (0b0011000001000100 = [ ...

The pagination, sorting, and filtering features in my Angular Material project seem to be malfunctioning

Having created a project on Angular CLI 7, I decided to incorporate Angular Material into it. Despite adding modules for table pagination, expansion, filter, and sort in the app modules file, I am facing difficulties making the paginator, sorting, and fil ...

I encountered an issue with TypeScript when attempting to post a message back to the source

Here is a snippet of my code window.addEventListener('message', (e) => { e.source.postMessage('hi there, I hear you!', '*'); }); Encountered an error: [ts] The type '((message: any, targetOrigin: string, transfer? ...

atom-typescript - What could be causing the unrecognized Typescript configuration options?

I'm puzzled as to why I am encountering the errors depicted in the screenshot below. Atom is indicating that my tsconfig.json file has 'project file contains invalid options' for allowJs, buildOnSave, and compileOnSave. However, according ...

Leverage Vue's ability to assign data from a parent component to

I am struggling to bind the data (inputData) from the parent component to my child component. I have checked my code multiple times but cannot find where the mistake is. MainApp.js let vm = new Vue({ el: "#app", components: { &ap ...

Unrestricted Angular Audio Playback without CORS Restrictions

I am currently developing a web application using Angular4 that will include the feature of playing audio files. Unfortunately, I am facing an issue where I do not have control over the server serving the media files, and therefore cannot make any modifica ...