jjoselon jjoselon - 3 years ago 164
Javascript Question

Ignore validation for an element html - Jquery validation

I've a form look like this:

<form action="..." name="editPost">
<div class="main">
<input type="text">
<input type="text">
<input type="text">
<input type="text">
<input type="text">
</div>

<ul class="form_template">
<li><input type="text" id="question1"></li>
<li><input type="text" id="question2"></li>
<li><input type="text" id="question3"></li>
<li><input type="text" id="question4"></li>
<li><input type="text" id="question5"></li>
</ul>
</form>


my js code is:

var validator = $("form[name='editPost']").validate();


and My goal is only validate
main
id fields and the rest doesn't validate.

And finally, my question is how to ignore validation for
form_template
class

Answer Source

ignore attribute only works with inputs, You can do a regular expression to ignore a set of inputs, but the conditions is that its names starts with the same name, for example, you have several fields like these:

        <input type="text" required="required" name="h1" id="goal1">
        <input type="text" required="required" name="h2" id="goal2">
        <input type="text" required="required" name="h3" id="goal3">
        <input type="text" required="required" name="h4" id="goal4">
        <input type="text" required="required" name="h5" id="goal5">

Watch out id attr, it starts with the same string, but it really are differents, finally config ignore attr like this:

            $("form[name='editPost']").validate({
               ignore: "input[id^='goal']"
            });
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download