Error animation on client-side validation not resetting correctly

Incorporated a form validation and error display system utilizing TransitionGroup for animations. The flag issueVisible manages the visibility of the error message, while determineField() aids in identifying the field related to the error.

The issue arises when validation errors on the client fail to trigger the animation consistently, unlike errors associated with serverError which do trigger the animation correctly. Despite setting issueVisible.value to false at the start of the login() function, the animation for validation error tends to show only once, and subsequent calls to login() reset the timeout but not the animation. To reset the animation, one must wait for it to disappear naturally after 3 seconds. Seeking a viable solution to this problem.

// template
<TransitionGroup name="bounce">
    <template v-if="issueVisible">
        <ItemFormError
            class="modal__error"
            :fieldName="determineField()"
            :issues="issues">
            <template #icon>
                <IconError class="modal__error-icon" />
            </template>
        </ItemFormError>
    </template>
</TransitionGroup>
// script
const issues = ref<
    FlatErrors<typeof LoginSchema>['nested'] & { server?: string }
>({});

const issueVisible = ref(false);

const determineField = () => {
    if (issues.value.username) return 'username';
    if (issues.value.password) return 'password';
    if (issues.value.server) return 'server';
    return '';
};

let timeout: number | undefined;

const login = async () => {
    const result = safeParse(LoginSchema, loginData, {
        abortPipeEarly: true,
    });
    issueVisible.value = false;
    if (timeout) {
        clearTimeout(timeout);
    }
    if (result.success) {
        issues.value = {};
        issueVisible.value = false;
        try {
            await storeAuth.login(loginData);
            if (storeAuth.serverError) {
                issues.value.server = storeAuth.serverError;
            } else {
                setTimeout(() => {
                    router.push({ name: 'home' });
                }, 3000);
            }
        } catch (err) {
            issues.value.server = storeAuth.serverError;
            issueVisible.value = true;
            timeout = setTimeout(() => {
                issueVisible.value = false;
            }, 3000);
        }
    } else {
        issues.value = flatten<typeof LoginSchema>(result.issues).nested;
        issueVisible.value = true;
        timeout = setTimeout(() => {
            issueVisible.value = false;
        }, 3000);
    }
};

Answer №1

We were able to resolve the problem by incorporating nextTick() into the login() method.

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

Utilizing titanium to develop a functionality that listens for button presses on any area of the screen

I am trying to simplify the action listener for 9 buttons on a screen. Currently, I have individual event handlers set up for each button, which seems inefficient. Is there a way to create an array of buttons and manipulate them collectively? For example ...

What are the capabilities of an INNER JOIN query in Objection JS?

Here is the data model that I am working with: https://i.stack.imgur.com/g1T5i.jpg In this model, a User can be associated with multiple Projects, and a Project can have many Users. These relationships are managed through a join table called UserProjects. ...

Experiencing a typeerror with the Event attribute

I encountered an issue while trying to target an event. Here is what I attempted: public gotoPage(event: Event): void { const gettest = (event.target as HTMLElement)?.getAttribute('href'); if (href) { const testModule = "valu ...

Having trouble retrieving textfield value with jQuery

On my website, I have an invoice.jsp page that requires jQuery to calculate values in textboxes. Within the invoice, there is a quantity textbox. When a user enters a quantity, the price should be dynamically calculated as (total_subPrice= unit_price * qu ...

Angular 2 decorators grant access to private class members

Take a look at this piece of code: export class Character { constructor(private id: number, private name: string) {} } @Component({ selector: 'my-app', template: '<h1>{{title}}</h1><h2>{{character.name}} detai ...

Can you provide an explanation for what the line "const { Nuxt, Builder } = require('nuxt')" is doing in this

Currently, I am working on a Nuxt project where I will be utilizing the Express framework on the server side. Upon setting up the Nuxt project and choosing the express option, I came across a new file named server/index.js which includes a basic template f ...

What is the process for cancelling a pending request using jQuery in JavaScript Selenium?

My website has a high volume of users clicking on one button. Waiting for long-pending ajax requests to get responses, sometimes over a minute, seems nonsensical. I understand how to wait for the response, but how can I cancel it? How do I cancel all pend ...

Error message: "The requested capacitor ionic 4 Vue project could not be found. Please check your files

After following a tutorial on Smashing Magazine about creating a new Vue project with Ionic and Capacitor, I added the necessary dependencies using yarn. However, when trying to run Electron with 'yarn run electron:start', I encountered a net::ER ...

Angular - handling Observable<T> responses when using Http.post

One issue I encountered was when trying to implement a method that returns an Observable. Within this method, I utilized http.post to send a request to the backend. My goal was to store the JSON object response in an Observable variable and return it. Howe ...

The risk of a race condition could arise when working with nested switchMaps in ngr

I am currently working on an Angular 9 application that heavily relies on observables. In a specific component, I have the following requirements: Retrieve all companies to access certain information. Fetch all responses and link additional company detai ...

Can qTip 2.0 be configured to use a different default attribute instead of 'title'?

Is there a way to set qTip to use an attribute other than 'title' as the default? I need to use another attribute because when I disable qtip and add elements dynamically with "title", the title still shows when I hover over the element, which i ...

The title of the Electron application remains consistent

My application is being packaged using electron-packager, but it's not changing its name and still displays "Electron." It's supposed to use the productName in my package.json file, but for some reason, it doesn't change. Even after creati ...

CSS transition fails to revert

My standard opacity animation is not working in reverse order. Here is a link to the JSFiddle example. According to the documentation, it should work automatically. Since I am new to JavaScript, I am unsure if this issue lies in my code or if the CSS anima ...

Having trouble adding a test card to the Google Pay testing environment and calculating the order total

How can I display the order total in GooglePay payment sheet? I could not find any documentation on this. Is it possible to do so? Even though I am using the TEST environment, I am unable to add any test card as mentioned in the URL provided below. Additio ...

Ways to Retrieve the Text From the Selected Index in Datalist Element

I need to extract the inner text of the option tag using pure JavaScript This is the HTML code I am working with: <input list="in" name="i_n" class="form-control" placeholder="Enter Item Name" required> <datalist id="in" onChange="rate(this)"&g ...

Search in the Firestore database for documents that have a field containing a reference to another document. Once those results are found, use the reference to conduct a second query

In an attempt to optimize the query that delivers details of all events a participant has attended, I have restructured my database schema. Events with participants are now linked through a subEvent subcollection in the users collection, storing document r ...

creating an interactive element that seamlessly integrates with a dynamic background image slideshow

Struggling to make this work correctly as a newbie in javascript. I need the background image to slide upon hover and stay active on its selected div when clicked. The html, css, and javascript I have currently work fine - when the user clicks on a div, a ...

Adding QML code into a Jade file

Currently working on developing a straightforward video streaming application using Node.js and integrating the WebChimera plugin. The player configuration is done in QML with Chimera, and I am facing numerous errors during the compilation process in Jade. ...

Is there a way to programmatically prevent the back button from functioning if the previous route pathname in React was 'Login'?

When it comes to navigating back on previous pages, the traditional back button is typically used instead of relying solely on the navigation bar. However, I am currently looking to disable this feature specifically when the next previous route in line is ...

Install Chakra UI in the latest Next.js project directory

Recently, I decided to incorporate Chakra UI v2.4.9 into my Next.js project running on version v13.1.6. To ensure a seamless integration, I followed the detailed instructions provided in Chakra UI's official guide for Next.js. However, I encountered s ...