Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9187575
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T19:48:15+00:00 2026-06-17T19:48:15+00:00

I am using jQuery (1.8.2) and the Validation plugin (1.10.0) to validate a form.

  • 0

I am using jQuery (1.8.2) and the Validation plugin (1.10.0) to validate a form. My problem is that when setting a custom invalidHandler, my form is submitted even when there are errors.

The long version

The form is quite long and has several fields that can be hidden from view (using jQuery.toggle()) to make the form easier to work with. Now, some of these fields are “optionally required”, i.e. I only care about their content if a corresponding checkbox is checked. So I have validators looking similar to this:

emailInvitationTitle: {
     required: function() {
        return $("#emailInvitation_chk").prop("checked");
    }
},
emailInvitationBody: {
    required: function() {
        return $("#emailInvitation_chk").prop("checked");
    }
}

So far, so good. However, if any of these “maybe hidden, maybe required” fields are invalid on submit, I want to show the relevant hidden sections (with class “messageEditor”). So I have an invalidHandler like this:

invalidHandler: function(form, validator) {
    // If either title or body is empty, make sure their parent div is visible
    if (!(validator.element("#emailInvitationTitle") 
            && validator.element("#emailInvitationBody"))) {
        $("#emailInvitationTitle").closest(".messageEditor").show();
    }
}

The issue is that it seems by defining this invalidHandler, my form is always submitted, regardless whether the validation succeeds or not. I dug around in jquery.validate.js and observed the following (at line 331 and onward):

    // http://docs.jquery.com/Plugins/Validation/Validator/form
    form: function() {
        this.checkForm();
        $.extend(this.submitted, this.errorMap);
        this.invalid = $.extend({}, this.errorMap);
        if (!this.valid()) {
            $(this.currentForm).triggerHandler("invalid-form", [this]);
        }
        this.showErrors();
        return this.valid();
    },

I won’t pretend I understand even half of it. But when tracing through this, I noticed that this.valid() correctly returns false on the first call, which causes my invalidHandler to trigger. However, return this.valid() yields true immediately after. Somehow the trigger (?) clears the validator’s errorList array, causing the invalid form to be submitted.

Is this a bug with the validate plugin, or jQuery itself (or something else)?

Any suggestions for a fix/workaround?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T19:48:16+00:00Added an answer on June 17, 2026 at 7:48 pm

    Answering my own question with the workaround I eventually came to use.

    I hacked around this problem by modifying the form function in jquery.validate.js:

    // http://docs.jquery.com/Plugins/Validation/Validator/form
    form: function() {
        this.checkForm();
        $.extend(this.submitted, this.errorMap);
        this.invalid = $.extend({}, this.errorMap);
        var errorListCopy = this.errorList.slice(); // hack, step 1
        if (!this.valid()) {
            $(this.currentForm).triggerHandler("invalid-form", [this]);            
            this.errorList = errorListCopy.concat(this.errorList); // hack, step 2
        }
        this.showErrors();
        return this.valid();
    },
    

    Still doesn’t quite feel like the right way to go about it, but it worked for me.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using the jQuery form validation plugin. The problem I have is that
I have a form that is using jQuery Validate plugin for client side validation,
I am using jquery.validate.js plugin for a dialog validation. My problem is that I
I'm try to validate form using jquery validation plugin my from code: source code
I'm using the Jquery Validation plugin to validate my form on the client before
I am using jquery validation plugin for form validation. I have added a custom
I have a form that validates using the jQuery plugin: Validation, v1.9.0. The validation
I am using http://bassistance.de/jquery-plugins/jquery-plugin-validation/ to validate a form which will allow a user to
I am using the jquery validation plugin to validate a form. I have the
I'm using the jQuery validation plugin to validate a form, and I'd like to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.