Nick D
Nick D

Reputation: 589

jQuery Validation Plugin not validating fields in a hidden div

I have the following div block which i'm trying to validate using the jQuery validation plugin

<div class="row" id="signupaddress1" hidden>
    <label for="id-31"><span>Address 1:</span><span class="mark">*</span></label>
    <input type="text" class="required" id="id-31" name="address1"/>
</div>

Then using

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

to validate the form. But if this div is hidden it appears to ignore the field when validating. The form uses a postcode lookup to populate the address fields and then displays the div when this has been populated but, as a result, if only the postcode is entered the form can be submitted without validating address1 contains anything.

Upvotes: 2

Views: 1888

Answers (2)

LoneWOLFs
LoneWOLFs

Reputation: 2306

I guess you are using the new validator plugin which ignores hidden fields by default. To overwrite that just use this and it will work.

ignore:""

You can refer to the Github repo for the change Changeset

Upvotes: 4

Deepak Kumar
Deepak Kumar

Reputation: 3751

You are telling jQuery to validate the form but where is your form tag you should do something like this

<form><div class="row" id="signupaddress1" hidden>
<label for="id-31"><span>Address 1:</span><span class="mark">*</span></label>
<input type="text" class="required" id="id-31" name="address1"/></div></form>

than use

$("form").validate(...); 

Upvotes: 0

Related Questions