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 6905555
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T08:11:52+00:00 2026-05-27T08:11:52+00:00

I am using the jquery validate plugin to validate all the fields on my

  • 0

I am using the jquery validate plugin to validate all the fields on my form, without issue.

However, I have a need to validate the form against the number of rows in an html table located outside the form markup.

Here are the elements in question:

  1. form: id = “roadForm”
  2. select input: id = “editRoad_ProjectClassification”
  3. table: id = “dataExistingSegments”

My business rule goes something like this:

  1. If the value of “editRoad_ProjectClassification” select is equal to “NO TREATMENTS”, then the number of rows in the table “dataExistingSegments” must be equal to zero.
  2. If the value of “editRoad_ProjectClassification” select is not equal to “NO TREATMENTS”, then the number of rows in the table “dataExistingSegments” must be greater than zero.

I have created two custom rules for the validator as follows:

  1. To verify there are no rows in the table if “editRoad_ProjectClassification” is equal to “NO TREATMENTS”.

    g$.validator.addMethod("roadWithNoTreatmentsHasNoSegments", function (value, element, params) {
    var pc = g$('#editRoad_ProjectClassification').val();
    var segmentCount = g$('#dataExistingSegments tbody tr').length;
    
    if (pc == 'NO TREATMENTS' && segmentCount > 0) {
        return this.optional(element) || false;
    }
    else {
        return this.optional(element) || true;
    }
    }, g$.format("Must have no segments if Project Classification is 'NO TREATMENTS'")
    );
    
  2. To verify that there is at least one row in the table if “editRoad_ProjectClassification” is not equal to “NO TREATMENTS”

    g$.validator.addMethod("roadWithTreatmentsHasAtLeastOneSegment", function (value, element, params) {
    var pc = g$('#editRoad_ProjectClassification').val();
    var segmentCount = g$('#dataExistingSegments tbody tr').length;
    
    if (pc != 'NO TREATMENTS' && pc != '' && segmentCount == 0) {
        return this.optional(element) || false;
    }
    else {
        return this.optional(element) || true;
    }
    }, g$.format("Must have at least one segment if Project Classification is not 'NO TREATMENTS'")
    );
    
  3. Then to validate the form, I have the following:

    g$("#roadForm").validate({
    errorElement: "span",
    rules: {
        editRoad_Jurisdiction: "required",
        editRoad_TreatmentDate: {
            "required": true,
            date: true,
            roadDateIsValidForMultiYearPlan: true
        },
        editRoad_ProjectClassification: "required",
        editRoad_ImprovementType: "required",
        editRoad_SurfaceType: "required",
        editRoad_MultiYear: "required",
        editRoad_LifeExpectancy: {
            "required": true,
            digits: true
        },
        editRoad_MDOTJobID: {
            digits: true
        },
        editRoad_ProjectID: {
            maxlength: 50
        },
        dataExistingSegments: {
            "required": true,
            roadWithTreatmentsHasAtLeastOneSegment: true,
            roadWithNoTreatmentsHasNoSegments: true
        }
    },
    messages: {
        editRoad_Jurisdiction: "Please select an option",
        editRoad_TreatmentDate: {
            required: "Please select an date",
            date: "Please enter a properly formatted date"
        },
        editRoad_ProjectClassification: "Please select an option",
        editRoad_ImprovementType: "Please select an option",
        editRoad_SurfaceType: "Please select an option",
        editRoad_MultiYear: "Please select an option",
        editRoad_LifeExpectancy: {
            required: "Please enter a value",
            digits: "Must be a valid number"
        },
        editRoad_MDOTJobID: {
            digits: "Must be a valid number"
        },
        editRoad_ProjectID: {
            maxlength: "Cannot be more than 50 characters long"
        }
    }
    });
    

This is not working, and I assume it is because the “dataExistingSegments” table is not located within the form. But due to the way the markup and css is done, I can’t place this table within the form. How can I get this to work?

  • 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-05-27T08:11:53+00:00Added an answer on May 27, 2026 at 8:11 am

    Well, I figured it out and thought I should post here for anyone else who may need to do this.

    I made a text input inside the form and styled it so that it looked like a label, and disabled it so that users couldn’t type in it.

    I then assigned the validation rules to this input, instead of to the table. And now the validation works and the error message appears properly.

    One other thing, I experimented with hiding the input. I was hoping the input would be hidden, but the validation message would still show up. But apparently the jquery validate plugin does not apply validation to any hidden fields in the form. So that didn’t work. The input had to be visible, which is why I styled it to look like a label, and disabled it (to work like a label).

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

Sidebar

Related Questions

I'm using jQuery validate plugin. I have 3 fields, and need to validate them
I have a form that is using jQuery Validate plugin for client side validation,
I have some strange issue using jQuery Validation plugin. Firs of all here is
I'm using the jQuery validation plugin to validate a form. The form fields are
I'm using jquery's popular Validate plugin to validate all my fields. This works great
I'm currently using this jQuery validate plugin and having an issue in IE where
I'm using the jQuery validate plugin to validate a multi-step form like this one:
How to validate special characters in a textbox without using Validate plugin on JQuery
I'm not using any jQuery plugin to validate the form, just plain jQuery. My
I'd like to validate a form using the jquery validate plugin, but I'm unable

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.