Reforming a form when connecting a jquery validation plugin

I have a simple form, as shown below, that I added the jQuery validation plugin to ( http://docs.jquery.com/Plugins/Validation ). I have this form in a modal popup, so if there are errors and the user closes the window when they open it again, the form still has errors. In my popup callback, I tried calling resetForm (), but it says the method does not exist.

HTML form:

<form class="validations" id="commentForm" method="get" action=""> <p> <label for="name">Name</label> <em>*</em><input id="name" name="name" size="25" class="required" minlength="2" /> </p> <p> <label for="email">E-Mail</label> <em>*</em><input id="email" name="email" size="25" class="required email" /> </p> </form> 

Popup Close Callback:

 function(){ $(this).find('form.validations').resetForm(); } 

Thanks in advance for your help.

+4
source share
2 answers

resetForm is part of the object returned by the validation method, not a form. Example:

 var validate = $('#commentForm').validate({ ... }); // Later... validate.resetForm(); // Or if variable scope is in the way... $('#commentForm').data('validator').resetForm(); 

The validation plugin contains a link to the validation object in the form data warehouse.

+9
source

If this is a really short form with several elements, you can simply reset them manually when the close button in the modal window is pressed, for example:

$("input[name='formelementName']").val("");

+1
source

All Articles