Use $("#age").removeClass("required"); The rules method doesn't affect inline metadata (eg. classes, attributes). And required is a class here, not an attribute.
Jörn On Tue, May 19, 2009 at 10:26 PM, Sasha <sasha.akh...@gmail.com> wrote: > > Hello world, > > From everything I can understand from the doc, this code > ------ > <form id="myForm"> > <input type="text" class="age required" id="age"/> > <input type="checkbox" id="checker"/> click me. > <input type="submit"/> > </form> > <script> > $(document).ready(function(){ > $("#myForm").validate(); > $("#checker").bind("click keypress", function(){ > $("#age").rules("remove"); > $("#age").removeAttrs("required"); > alert($("#age").rules().required); > }); > }); > </script> > ----- > ought to mean that when the "checker" checkbox is clicked, "false" is > shown in an alertbox, and the "required" rule on the "age" field is > removed, so that the form passes validation afterward. > > However, I see "true" when I click the checkbox, and the form doesn't > pass validation after that (when the submit button is clicked, it > fails validation and the "this field is required" message appears). > > Help?