HOW TO ENABLE AND DISABLE REQUIRED VALIDATION GROUP FOR FIELDS AND EXPRESSIONS FIELDS WHEN A DIV IS SHOWN

Ankit Singh

Total Post:341

Points:2389
Posted by  Ankit Singh
C#
 895  View(s)
Ratings:
Rate this:

I have a credit card transaction area in my form that I hide and show based on user's selection in an radio button group. 

With my credit card piece are required validations and required expressions that is in a validation group. 

I was wondering if I could get some help with enabling and disabling this validation group in JQuery. 

Thanks in advance.

  1. Sumit Kesarwani

    Post:378

    Points:2694
    Re: How to enable and disable Required Validation group for fields and Expressions fields when a div is shown

    I usually have a class that indicates whether a field should be validated or not, so when a field that should be validated is hidden, just remove the class. Add it again when it is displayed.

    A more elegant solution is to disable validation of hidden fields:

    $('myform').submit(function() {

        $('myform').find('validate:visible').forEach( ... );

    });

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!