Troubleshooting: Vee-validate useResetForm not functioning properly during submission in Vue 3 with Typescript

I've been struggling to reset form data after submission, and it seems like the useResetForm hook isn't working as expected.

Code Section

<script setup lang="ts">
  import CircularProgress from "@/components/CircularProgress.vue"
  import { Field, Form, useResetForm } from "vee-validate"
  import * as Yup from "yup"
  import { useLazyQuery, useResult } from "@vue/apollo-composable"
  import { FORGOT_PASSWORD } from "./gql"

  const { loading, load, error, result } = useLazyQuery(FORGOT_PASSWORD)

  const schema = Yup.object().shape({
    email: Yup.string().required("Email is required").email("Email is invalid"),
  })

  const onSubmit = async (value: Record<string, any>) => {
    let variables = value

    load(undefined, variables)

    let res = useResult(result, null, (data) => data.forgotPassword)

    useResetForm() // Not functioning properly
  }
</script>
<h3>This is the template structure I have:</h3>
<pre><code><div class="flex-auto px-4 lg:px-10 py-10 pt-0">
   <Form
     @submit="onSubmit"
     :validation-schema="schema"
     v-slot="{ errors }"
   >
      <div class="relative w-full mb-3">
        <label
           class="block uppercase text-gray-700 text-xs font-bold mb-2"
           for="grid-password"
        >
          Email
        </label>
        <Field
          name="email"
          type="email"
          :class="{ 'border-rose-500 border-2': errors.email }"
          class="border-0 px-3 py-3 placeholder-gray-400 text-gray-600 bg-white rounded text-sm shadow focus:outline-none focus:ring-2 focus:ring-sky-400 w-full"
          placeholder="<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="acc9d4cdc1dcc0c9ecc6c3c4c2c8c3c982c5c3">[email protected]</a>"
          style="transition: all 0.15s ease 0s"
        />
          <p class="text-red-500 mt-1 text-xs">
            {{ errors.email }}
          </p>
          <p
            v-if="error?.message"
            class="text-red-500 mt-1 text-xs"
           >
             {{ error?.message }}
          </p>
        </div>
        <div class="text-center mt-6">
          <button
            class="bg-blue-600 text-white active:bg-blue-800 text-sm font-bold uppercase px-6 py-3 rounded shadow hover:shadow-lg outline-none focus:outline-none mr-1 mb-1 w-full flex justify-center align-center"
            type="submit"
            style="transition: all 0.15s ease 0s"
           >
             <CircularProgress v-if="loading" />
             Send Reset Link
           </button>
        </div>
   </Form>
</div>

Answer №1

Utilize the

formActions: FormActions<any>
property within the onSubmit event.

Illustrated below is an example:

const onSubmit = (model, formActions) => {
  formActions.resetForm()
}

Furthermore, in your HTML:

  <Form
     @submit="onSubmit"
     :validation-schema="schema"
     v-slot="{ errors }"
   >

Refer to the documentation for more information:

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

Can you explain how to utilize multiple spread props within a React component?

I'm currently working in TypeScript and I have a situation where I need to pass two objects as props to my React component. Through my research, I found out that I can do this by writing: <MyComponent {...obj1} {...obj2} /> However, I'm fa ...

Utilizing dynamic arguments in TypeScript to recycle types

Can I accomplish this with TypeScript? Here is the source code I currently have: interface FormStore<T> { type: T; } interface Form<T> extends FormStore<T> { email: T; phone: T; password: T; } interface FormState<R> { fo ...

Issue with Async Pipe when connected to a recently generated observable is causing failures

Encountering an error when trying to use the Async Pipe with a newly created Observable? "Cannot read property 'subscribe' of undefined" Check out this Plunkr for a demonstration: https://plnkr.co/edit/vljXImCYoNubjyxOaWo3?p=preview If you com ...

Adding typing to Firebase Functions handlers V2: A step-by-step guide

Here's a function I am currently working with: export async function onDeleteVideo(event: FirestoreEvent<QueryDocumentSnapshot, { uid: string }>): Promise<any> { if (!event) { return } const { disposables } = event.data.data() ...

The process of linking a Json response to a table

In my products.components.ts class, I am retrieving Json data into the variable this.Getdata. ngOnInit() { this._service.getProducts(this.baseUrl) .subscribe(data => { this.Getdata=data this.products=data alert(JSON.stringify(this.Getdata)); ...

Creating a dropdown menu in Bootstrap 5 without using any of the Bootstrap

In my Angular application, I have a header with icons and pictures that I would like to use as dropdown menus. The code snippet for this functionality is shown below: <li class="nav-item dropdown"> <a class="nav-li ...

Transform Loopback 4 filter into a SQL WHERE condition

When using Loopback 4, the filter object that is received by functions like Get and Count appears as shown below: { where: { property: { op: value; } } } I am interested in converting this structure into an SQL WHERE clause to use it in ...

Why am I having trouble iterating through my array object?

Trying to showcase the contents of object within an array. However, unable to showcase any results. Why is this happening? This is what I've attempted so far: Demo available here: https://stackblitz.com/edit/ionic-dsdjvp?file=pages%2Fhome%2Fhome.ts ...

Utilizing nested namespaces for optimal organization and clarity

Is it possible to export a namespace A with another namespace B nested within it? For example: // b.ts export namespace B { export const val = 'val'; } // a.ts export namespace A { //... some thing import B as namespace } --- the above wil ...

How to Set Focus on an Input Field in an Angular 2 Modal

I'm currently working with modals in an angular project and I have a requirement to focus on a specific field within the modal. This particular field is a part of a @component: Autocomplete.html <div #autocomplete> <input #input requ ...

Utilize SWR in NextJS to efficiently manage API redirection duplication

When using SWR to fetch data, I encountered an error where the default path of nextjs was repeated: http://localhost:3000/127.0.0.1:8000/api/posts/get-five-post-popular?skip=0&limit=5 Here is my tsx code: 'use client' import useSWR from &quo ...

Encrypting and decrypting data using RSA in TypeScript

Currently, I am utilizing Angular 4 to develop the front end of my application. For authentication, I have integrated OAuth2 on the backend (which is created using Spring in Java), ensuring that only authorized individuals can access my app. However, ther ...

Exploring Vue 3's Methods for Sending Data to Vuex Store within the Setup Phase

I'm currently working on a project that involves Vue 3 and Vuex. This is my first time using Vue 3, and I'm having trouble accessing Vuex within the Setup method of my Vue 3 project. Specifically, I have a feature object that is set by a Childco ...

Assign a value to a variable using a function in Typescript

Is there a way in typescript to explicitly indicate that a function is responsible for assigning value to a variable? UPDATED CODE Here, the code has been simplified. While getText() ensures that it will never be undefined, this may not hold true in subs ...

Guide to setting up .env Variables on a DigitalOcean Ubuntu droplet

After deploying my Node.js app on a DigitalOcean Ubuntu droplet, I encountered the need for variables from my .env file. How can I go about creating these variables within the DigitalOcean droplet? ...

Leveraging editor.action.insertSnippet from a different plugin

I am attempting to enhance the functionality of VS Code by adding buttons to the status bar that automatically insert code snippets. I am utilizing this Extension for this purpose. Additionally, I have configured keybindings in my keybindings.json file whi ...

In Typescript, is there a specific type for images encoded in base64 format?

As a newbie to Typescript, I am diligently typing everything precisely as part of my learning journey. A property called lqip (low quality image placeholder) is being pulled from a CMS and should be a base64 encoded image. It's clearly a string, but ...

Transfer dynamically generated table data to the following page

Seeking guidance on a common issue I'm facing. I am creating a table using data from Firebase upon page load, and I want users to click on a row to view specific details of that item. It may sound confusing, but it will make more sense with the code p ...

Create a TypeScript interface that represents an object type

I have a Data Structure, and I am looking to create an interface for it. This is how it looks: const TransitReport: { title: string; client: string; data: { overdueReviews: number; outstandingCovenantBreaches ...

How come TypeScript tuples support the array.push method?

In the TypeScript code snippet below, I have specified the role to be of Tuple type, meaning only 2 values of a specified type should be allowed in the role array. Despite this, I am still able to push a new item into the array. Why is the TS compiler not ...