jquery validation required
I tried this but it doesn't seem to work,,, any Idea why not ?
I call validation that way : $("#aspnetForm").validate().form();
and the "details" field is allways required no matter if the "other" checked or not ....
I took the example from http://jquery.bassistance.de/api-browser/plugins.html#jQueryval开发者_开发知识库idatormethodsrequiredStringElementBooleanStringFunction
10X!!
Make sure to include all the necessary scripts: jquery.js
, jquery.validate.js
and jquery.metadata.js
(if you are using class metadata to define validation rules)? Here's a sample:
<html>
<head>
<title>Test</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script type="text/javascript" src="http://ajax.microsoft.com/ajax/jquery.validate/1.5.5/jquery.validate.min.js"></script>
<script type="text/javascript" src="http://dev.jquery.com/view/trunk/plugins/validate/lib/jquery.metadata.js"></script>
<script type="text/javascript">
$(function() {
$('#aspnetForm').validate();
$('a').click(function() {
alert($('#aspnetForm').validate().form());
return false;
});
});
</script>
</head>
<body>
<form id="aspnetForm" action="#">
<input name="other" type="radio" />
<input name="details" type="text" class="{required:true}" />
<input type="submit" value="OK" />
</form>
<a href="#">Validate</a>
</body>
</html>
the answer :
<input id="other" type="checkbox" />
<br/>
<input class="{required:'#other:checked', messages:{required:'if you check it then fill it'}}" />
code works ! 10X Darin Dimitrov anyway ...
精彩评论