"Troubleshooting a CSS Animation Problem: Button Animation Glitch

I was working on a code snippet with the following structure:

shakingErr class from CSS was not being applied correctly when the user clicked submit with empty/wrong fields. How can this be resolved so that the shaking error animation is triggered properly?

Additionally, there's another animation that plays on the button click. What changes can be made to only trigger this animation after all input fields are filled correctly?

Desired Outcome

To better understand the requirements, refer to the video demonstration at this link. The goal is to have the error animation activate when the user tries to submit empty/wrong fields, while ensuring that the button animation is only activated upon successful form completion.

Answer №1

First and foremost, I recommend updating the HTML structure of the submit button for better semantics:

<button class="button" type="submit">
   <div class="text">Submit</div>
</button>

Next, let's address what occurs when the user clicks on the submit button:

$(".button").click(function(e) {
  e.preventDefault();
  let validationOK = true;
  
  // Data validation
  const form = document.forms.myform;
    let data = Object.fromEntries(new FormData(form).entries())
    for (let entrie in data) {
      if (!form[entrie].checkValidity()) {
        validationOK = false;

        // Error animation
        form[entrie].classList.add('shakingErr')
        setTimeout(() => {
          form[entrie].classList.remove('shakingErr')
        }, 820)
      }
    }
    
  if (validationOK) {
    basicTimeline.play();

    // Execute the submit action here
  }
});

// JavaScript code snippet with animations and timeline setup goes here...
// CSS styling for contact form elements, buttons, and animations...
<!DOCTYPE html>
<html>

<head>
  // Head section content goes here...
</head>

<body>
  <!-- Contact form section -->
  <section id="contact">
    // HTML content for contact form section...
  </section>
  <script src="script.js"></script>
</body>

</html>

An additional update is needed to ensure that input elements' border-color highlights correctly.

To fix this CSS issue, we should strengthen the error style override like so:

form .shakingErr {
  border-color: red;
  animation: shake 0.82s forwards;
}

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

Is it possible to change XML using Ajax technology?

Is it possible to update a value in an XML file using JavaScript/Ajax? I've managed to access the XML file with Ajax and utilize its values in my script. Now, I want to send any updates made by the script back to the XML file on the server using Ajax ...

Utilize Javascript to interpret a structure that resembles JSON

My data resembles JSON, with columns and names listed: columns: [ { allowNull: false, autoEnterSubType: 0, autoEnterType: 2, creationOrderIndex: 0, dataType: 4, databaseSequenceName: "seq_admintraties_adminratie_id", flag ...

Automatically resizing a multi-part CSS background based on content dimensions

My current CSS project has hit a snag that I can't seem to solve: There is a box on the left side of the site that contains three images - a top image, an optional and stretched middle image, and a bottom image. I want this left box to automatically ...

The column is experiencing difficulty in dividing evenly

https://i.sstatic.net/TOgOl.jpghttps://i.sstatic.net/gDuet.pngThe column is not splitting properly. I want the bottom picture to be positioned below the picture above. Adjusted column and image sizes <div class=" container mx-auto mt-5 p-0"> ...

Accessing UPI apps such as Google Pay through deep linking from a web application

I am currently exploring the possibility of deep-linking to individual UPI apps, like Google Pay, that are installed on a user's phone. The goal is for users to be seamlessly redirected to their preferred UPI app when they click on the respective icon ...

Why will the experimental activation of React concurrent features in Nextjs 12 disable API routes?

I just upgraded to Next.js version 12 and set up some API routes (e.g. "/api/products"). These routes were functioning properly, but when I enabled concurrentFeatures: true in my next.config.ts, the API routes stopped working. The console display ...

What is the best way to showcase the outcome using the <table> tag in HTML with columns containing 50 records each, except for the final column?

I have developed a program that is currently creating 540 different numbers. My goal is to present these 540 distinct numbers in columns with 50 records each (except for the last column where there may be fewer than 50 records) using the HTML <table> ...

I'm struggling to retrieve a specific column of data from a JSON file. Does anyone know how to do this successfully?

I have a JSON file with various columns, but I only want to display the rdid column. I am new to learning node and still trying to figure things out. data [ {"edid":"r7vr8r", "rdid":"86596", "rssi":&qu ...

Why is my data not being sent to the controller in ASP.Net MVC when using @Ajax.ActionLink

In my ASP.Net MVC 5 project with Razor Engine, I am trying to create a page that displays products using AJAX. Below is the code I have written : HomeController : public ActionResult GoodDetails(int id) { Models.NishtmanDBEntities db = new N ...

Align the logo at the center of the webpage both vertically and horizontally

Seeking help in centering my logo (775 X 225) both vertically and horizontally on a webpage, with a link "Enter" positioned underneath it. <html> <head> <Title> My Website </Title> <style type="text/css"> //centerlogo CS ...

What is the best way to invoke a function in a class from a different class in Angular 6?

Below is the code snippet: import { Component, OnInit, ViewChild } from '@angular/core'; import { AuthService } from '../core/auth.service'; import { MatRadioButton, MatPaginator, MatSort, MatTableDataSource } from '@angular/mater ...

What causes the Invalid Form Body error to appear when using the Discord API?

While developing a Discord bot, I encountered an issue with creating a ping command. The error message received was as follows: (node:37584) UnhandledPromiseRejectionWarning: DiscordAPIError: Invalid Form Body embed.footer.icon_url: Scheme "flashybot& ...

Creating an array of objects using a constructor: a step-by-step guide

a) Here is an example of an array containing objects with various properties: [ { "Account": "1111-000", "Desc": "Accrued - Payroll & Payroll Tax", "Amount": "-8,459.88", "Partner": "RAP", "FY": "2018", ...

Failure to register Express Route

I am currently using express and facing some challenges with creating routes using express.Router. Below is my index.js file (npm main file): require('dotenv').config() const express = require('express') const loaders = require('. ...

I encounter an error if an element is not displayed when using the isDisplayed() method

My situation Going to a specific page Should I click the element that is displayed If the element is not displayed, just ignore it My function exports.checkButton = function (driver) { driver.findElement(By.css(".btn.btn-danger.pull-right.remove- ...

The ideal choice for a default background image in terms of style and dimensions

I'm using this code to set a background image for my website. body{ background: url('path_to_image'); background-size: 100%; } I find that the background-size property works well for handling different screen sizes. I'm creating ...

Regularly verify if a date has passed its expiration

Consider our situation: Our web app utilizes node with express, requiring a background process to monitor the creation dates of multiple posts and trigger specific events when they expire. These expiration dates are user-defined, leading to varying expira ...

Error encountered with the item properties in vue-simple-calendar 'classes'

For my Vue.js project, I am utilizing the npm calendar package called `vue-simple-calendar` and aiming to implement dynamic classes for each event item like background-color, etc. However, the `classes` property doesn't seem to be functioning as expec ...

Error: Functionality cannot be achieved

Looking for assistance in resolving this issue. Currently, I am attempting to register a new user and need to verify if the username already exists or not. Below is the factory code used for this purpose: .factory('accountService', function($res ...

Searching through an array for multiple values on the same key

I am currently working on dynamically generating a listview in jQuery. So far, I have been successful in creating the entire list dynamically. However, I now face the challenge of filtering, searching, or reducing my initial data: var recipes = [ { "name" ...