Eliminate error class in jQuery Validate once validation is successful

I'm having an issue with the jQuery Validate plugin.

Even after a field is successfully validated, the "error-message box" continues to be displayed.

How can I remove this box?

Here's my code:

CSS:

.register-box .field .has-error{
    border: 1px solid red !important;

}
.register-box .field .has-error.success {
    border:none !important;
}
.register-box .field .has-success{
    border: 1px solid #42CDA1 !important;
    background: #EEFBF7 !important;
    color: black !important;
    border-bottom: 0px !important;
}
.register-box .success > .error{
    border: 1px solid #42CDA1 !important;
}
.register-box .field .valid{
    border: 1px solid #42CDA1 !important;
}
.register-box .error{
    margin-left: 200px !important;
    float: left;
    width: 150px;
    max-width: 150px;
    text-align: left;
    color: red;
    background: red;
    color: white;
    font-weight: bold;
    font-size: 11px;
    -webkit-font-smoothing: antialiased;
    font-smooth: always;
    -moz-osx-font-smoothing: grayscale;
    padding: 5px 7px;

}

jQuery:

  $('#myform').validate({

            debug: true,
            errorClass: "has-error",
            errorElement: "div",
            errorContainer: $("#warning, #summary"),

            errorPlacement: function (error, element) {
                        var name = $(element).attr("name");
                        error.appendTo($("#" + name + "_validate"));
                        $("#" + name + "_validate").addClass('error');
                    },


            /*errorPlacement: function(error, element) {
                error.appendTo("#errorHolder");
            },*/
            success: function(label,element) {
                label.hide();
                //var parent = $('.success').parent().get(0); // This would be the <a>'s parent <li>.
                //$(parent).addClass('has-success');    
            },

            rules: {
                username: {
                     required: true
                },
                email: {
                    required: true,
                    minlength: 5
                }

        },

            highlight: function(element, errorClass) {
                    $(element).addClass(errorClass);
                },

        messages: {
                firstname: "Enter your firstname",
                lastname: "Enter your lastname",
                username: {
                    required: "Enter a username",
                    minlength: jQuery.format("Enter at least {0} characters"),
                    remote: jQuery.format("{0} is already in use")
                }
            },
        submitHandler: function (form) { 
            alert('valid form submitted'); 
            return false; 
        }
    });

HTML:

<div class='register-box'>
  <form  id="myform" class="register-form">
    <?php 
        if($checksuccess){ alert("success",$success); }
        if($checkerror){ alert("error",$error);
        }
    ?>
    <div class="field">
      <label for="username">Username</label>
      <div id="username_validate"></div>
      <input type="text" name="username"  value="" placeholder="Enter your desired username"/>
    </div>
    <div class="field">
      <label for="email">E-mail</label>
      <div id="email_validate"></div>
      <input type="email" name="email" value="" placeholder="Enter a valid e-mail address"/>
    </div>
    <button class="login-btn" data-disable-with="Signing In..." name="login" type="submit">Sign In</button>
  </form>
</div>

Please see this jsFiddle for an example: http://jsfiddle.net/5eb3pctr/

If you enter something in the first input field, it validates with a green border, but the red "error-box" remains visible.

Answer №1

When you achieve Victory, remember to eliminate the mistake attribute that was added to your error container section

Here is how your code should appear;

victory: function(label,element) {
    label.parent().removeClass('mistake');
    label.remove(); 
},

DEMO

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

Enhance your table layout with Bootstrap 3 by adjusting textarea size to fill

I am currently in the process of developing a forum and bulletin board software. I am facing some challenges while trying to integrate a reply section into the thread page. You can view what I have implemented so far here. Html: <div class="panel pane ...

What could be the reason that my Bootstrap design is displaying narrower than the designated container?

Having some issues with a JavaScript code that involves innerHTML, causing a discrepancy in width compared to the CSS and Bootstrap rules I have set up. Below is the JavaScript code snippet: let numeroStreams = document.getElementById('num') let ...

Can Angular i18n facilitate language switching?

My objective is to switch the language from English (United States) to Indonesia using a button. View Source Code The issue is that the tutorial does not cover how to implement the language change feature. Why opt for Angular i18n over a custom helper? ...

Issue with CSS style on header with hyperlink

My CSS style includes a hyperlink for the "Title" to quickly navigate back to the home page. However, when I insert a table, this hyperlink gets disabled. /* JavaScript */ .header { position: absolute; height: 85px; right: 0; top: 0; left: 0; padding: ...

How to Manage Empty Lines in HTML Documents within WordPress

Just recently, I launched my brand new website. Everything seems to be functioning properly except for one issue that I discovered in the HTML source code. There are 15 blank lines before "<!doctype html>", which is causing some problems with SEO and ...

Issue with Material UI dropdown not selecting value on Enter key press

I have encountered an issue with the material UI dropdown component that I am using. When I navigate through the dropdown options using arrow keys and press enter, the selected value does not get highlighted. Below is the code snippet for the dropdown: ...

Focusing in on the mouse location to magnify a THREE.js element

I am currently working on a project using THREE.js and I have encountered an issue with zooming the object. The zoom functionality is centered around the render position when using trackball controls, but I need it to be based on the cursor's position ...

React Application - The division is positioned centrally when run on local host, however, it does not retain its center alignment

I'm encountering an issue with deploying my create-react-app on github pages. The first image showcases my deployed app on github pages, but the image is not properly centered on the page as intended. https://i.stack.imgur.com/rOciT.jpg On the othe ...

Concealing certain options in a dropdown list with jQuery Chosen

My app has a unique feature where it displays different dropdown lists based on previous selections. Specifically, I have two lists - one for vehicle Makes and the other for Models. When a specific Make is chosen, like BMW or Audi, the next list will only ...

Ways to retrieve a variable from a separate TypeScript document

A scenario arises where a TypeScript script contains a variable called enlightenFilters$: import { Component, Input, OnInit } from "@angular/core"; import { ConfigType, LisaConfig } from "app/enrichment/models/lisa/configuration.model"; ...

showcasing real-time webcam information within an HTML web application

I have successfully integrated my webcam data live into my web application using the following code snippet. The live feed from my webcam is now visible on the webpage. <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta ...

How can I dynamically generate multiple Reactive Forms from an array of names using ngFor in Angular?

I am in the process of developing an ID lookup form using Angular. My goal is to generate multiple formGroups within the same HTML file based on an array of values I have, all while keeping my code DRY (Don't Repeat Yourself). Each formGroup will be l ...

Send the user authentication form to a different location by using an AJAX request

I am in the process of developing a .Net Web application using ASP MVC, jQuery & AJAX. Within this application, I have a list of products. When a user clicks on the detail button of a specific product, they are taken to a details view which includes an "Ad ...

Encountering a TypeError when attempting to read the property 'name' of undefined while submitting a form in node.js

I'm currently working on a node Js project and I'm encountering an issue while saving form values to a mongoDB database. I've been troubleshooting but can't seem to pinpoint the cause of this error. The error is occurring at the router. ...

Tips on preventing &ersand symbols from being processed through ajax requests, while preserving them as plain text

One challenge I am facing is with my comment form submission through ajax. Below is the ajax code snippet: $('#button').click(function(){ comment = $('#comment').val(); $.ajax({ type : 'POST', url ...

React Native - Listview triggering multiple refreshes when pulled down

As I attempt to implement the onScroll function for ListView to detect when a user has pulled the list down beyond a certain pixel value in order to trigger an AJAX call and refresh the list, I am facing an issue where it fires multiple times leading to a ...

Creating an error handler in PHP for dynamically adding or removing input fields is a crucial step in ensuring smooth and

I designed a form with multiple fields, including a basic input text field and dynamic add/remove input fields. I successfully set the first field as required using PHP arguments, but I'm struggling to do the same for the additional fields. I need as ...

Nothing is in the Laravel array when using `$request->all()`

In the process of developing a shopping cart using Laravel. Here are the details : Routes : Route::post('/cart/add', 'CartController@store')->name('cart.store'); Route::patch('/cart/{product}', 'CartContro ...

Update Material-ui to include an inclusive Datepicker widget

I have integrated the Material-ui Datepicker into my website to allow users to download timed event information from a database. The issue I am facing is that when users select two bracketing dates, events for the end date are not showing up correctly. F ...

Flickering observed in AngularJS UI-Router when navigating to a new route

In my AngularJS ui-router setup, I am facing an issue with flickering during state changes while checking the authentication state. When a user is logged in, the URL /#/ is protected and redirects to /#/home. However, there is a brief flicker where the c ...