jQuery Validation Plugin: Packer undefined error?
Posted
by Rosarch
on Stack Overflow
See other posts from Stack Overflow
or by Rosarch
Published on 2010-05-14T20:29:48Z
Indexed on
2010/05/14
20:34 UTC
Read the original article
Hit count: 233
I'm using the jQuery validation plugin from bassistance.de. It works fine.
From <head>
:
<script type="text/javascript" src="/static/JQuery.js"></script>
<script type="text/javascript" src="/static/js-lib/jquery.validate.pack.js"></script>
<script type="text/javascript" src="/static/js-lib/jquery.validate.additional-methods.js"></script>
At first, this was the only validation code I had, and it worked:
$("form").validate();
$("#form-username").rules("add", {
required: true,
email: true,
});
It was validating this HTML:
<form id="form-username-form" action="api/user_of_email" method="get">
<p>
<label for="form-username">Email:</label>
<input type="text" name="email" id="form-username" />
<input type="submit" value="Submit" id="form-submit" />
</p>
</form>
Great, everything works. But then I add this JS:
$("#form-choose-options input[type='text']").rules("add", {
number: true,
});
to validate this markup:
<form id="form-choose-options" action="api/set_options" method="get">
<p>
<label for="form-min-credits">Min credits per term:</label><input type="text" name="min_credits" id="form-min-credits" /> <br />
<label for="form-optimal-credits">Optimal credits per term:</label><input type="text" name="optimal_credits" id="form-optimal-credits" /> <br />
<label for="form-max-credits">Max credits per term:</label><input type="text" name="max_credits" id="form-max-credits" /> <br />
<label for="form-low-GPA">Lowest acceptable GPA:</label><input type="text" name="low_GPA" id="form-low-GPA" /> <br />
<label for="form-high-GPA">Highest realistic GPA:</label><input type="text" name="high_GPA" id="form-high-GPA" /> <br />
<input type="hidden" class="user-pk" name="pk"/>
<input type="submit" value="Submit" />
</p>
</form>
This causes a javascript error on document load:
$.data(f.form, "validator") is undefined
The error is from the packer
function.
What am I doing wrong?
© Stack Overflow or respective owner