Search code examples
jqueryvalidationparenthidden

Jquery validator - Validate only elements with parents visible


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" .


Solution

  • $("#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")