1

I am using jquery validation for required field vaidation.

$("#myform").validate();

How ignore from validation the required elements with parents hidden?

Eg.

 <div id="general" style="display: none;">
    <input type="text" class="required" minlength="4"  name="project_name" id="project_name" tabindex="1" maxlength="255" value="project_name" />
    <input type="text" class="required" minlength="4"  name="project_managers" id="project_managers" tabindex="2" maxlength="255" value="project_managers" />
</div>
<div id="folders">
    <input type="text" class="required" minlength="4"  name="folder_name" id="project_name" tabindex="3" maxlength="255" value="project_name" />
    <input type="text" class="required" minlength="4"  name="folder_managers" id="project_managers" tabindex="4" maxlength="255" value="project_managers" />
</div>

In this situation i want to ignore from validation the elements from hidden div - "general" .

vasilenicusor
  • 2,023
  • 1
  • 21
  • 37
  • try this http://stackoverflow.com/questions/7349902/jquery-validator-validating-visible-elements-only – Sibu Nov 21 '12 at 12:26

1 Answers1

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

But as of version 1.9.0, that is the default and should not have to be declared.
See http://docs.jquery.com/Plugins/Validation/validate (select "options" and scroll down to "ignore")

st3inn
  • 1,556
  • 9
  • 17
  • Thanks, its works. I was used `$("#myform").validate({ ignore: [], rules: { ... } });` – vasilenicusor Nov 21 '12 at 12:50
  • The same situation, but the form is splited in accordion and i want to validate all visible elements from all ui-accordion-content . By default, jquery validate ignore the hidden elements but in this case the visible elements from colapsed accordion are ignored. – vasilenicusor Nov 21 '12 at 15:41
  • You could add a classname, eg. `ignore-validation` to the ones you want to ignore, adding `.addClass("ignore-validation")` when you collapse a `
    ` and `.removeClass("ignore-validation")` when you expand. Then specify `ignore: ".ignore-validation"` in the call to `validate()` to only validate the expanded `
    `s
    – st3inn Nov 21 '12 at 15:51
  • but i want to validate all visible elements from all collapsed or expanded ui-accordion-content. – vasilenicusor Nov 21 '12 at 17:00