views:

112

answers:

2

hello,

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#jQueryvalidatormethodsrequiredStringElementBooleanStringFunction

10X!!

A: 

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"&gt;&lt;/script&gt;
    <script type="text/javascript" src="http://ajax.microsoft.com/ajax/jquery.validate/1.5.5/jquery.validate.min.js"&gt;&lt;/script&gt;
    <script type="text/javascript" src="http://dev.jquery.com/view/trunk/plugins/validate/lib/jquery.metadata.js"&gt;&lt;/script&gt;
    <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>
Darin Dimitrov
I included all the necessary scripts: jquery.js, jquery.validate.js and jquery.metadata.jsmy code :<input id="other" type="checkbox" /> <input name="details" class="{required:'input[@name=other]:checked'}" />but still the input is required in submit, even if the checkbox is un checked .....
haddar
A: 

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

haddar