John Magnolia
John Magnolia

Reputation: 16793

jQuery validate resetForm not working added to Onclick checkbox

I wrote a small script which copies the billing address to the delivery address form fields onclick of a checkbox.

I have added validate.resetForm(); as suggested here: to ensure that the current form errors are cleared.

This doesn't seem to be working and clearing no errors.

Example: http://jsfiddle.net/c5Qkt/

Steps:

  1. Click the "Save" button, displays error messages.
  2. Enter details in "Billing Address"
  3. Check the "Same as Booking information"

How can I clear all errors and maybe even re-validate the form after click the checkbox?

Upvotes: 1

Views: 1364

Answers (1)

Rup
Rup

Reputation: 34408

Your problem is that resetForm is a method on the validator object returned by validate.validate(...), and not on the jQuery object itself. Fixed fiddle http://jsfiddle.net/pjucc/

var theForm = $(".validate");
var validate = null;
if (theForm.length) {
    validate = theForm.validate({ ... });
}
:
validate.form();

The function you want to trigger validation instead is .form()

Upvotes: 3

Related Questions