0

In my html page i have 24 fields which have their class = "emi".

Out of these 24 0 , 6 ,12 ,18 or 24 of them can be visible based on the value of a dropdown on my page.

Now i have to perform validations only on the elements which are visible.

I have used jQuery's .hide() and .show() to hide and show these elements

Abhishek Singh
  • 10,243
  • 22
  • 74
  • 108

4 Answers4

1

Try this..

// You will get array of visible controls by this code
var elementsToValidate = $('.emi:visible'); //or $('.emi').filter(':visible');
// perform validation using elementsToValidate
Paritosh
  • 11,144
  • 5
  • 56
  • 74
1

you can ignore the hidden elements like this

$("#myForm").validate({
  ignore: ":hidden",
   rules: {
    name: "required",
    age: "required",
    height: "required"
    }
 });

as in this link jquery validator - Validating visible elements only

Also you can do it like this using the not

$("#myForm").validate({ignore:":not(:visible)"});
Community
  • 1
  • 1
0

use the ignore option and set

$("#myform").validate({
    ignore: ".ignore"
});

OR

$("#myform").validate({
    ignore: ":hidden"
});

of jQuery validate. You can find it in http://jqueryvalidation.org/validate/.

Marikkani Chelladurai
  • 1,430
  • 1
  • 13
  • 23
0

This should be like

$("#myForm").validate({ignore:":not(:visible)"});

use

not(:visible)

instead of ":hidden"

Abhinav bhardwaj
  • 2,657
  • 25
  • 21