Duplicate Errors Using jquery.validate on Dynamic Forms

I have a form that clones a div upon clicking an add button. For validation I use the jquery.validate plugin. When the add button is clicked, I exectute the following to clear the errors.

validator.resetForm();

However, if inline errors are displayed before this being called, and then they are displayed again after the form is reset, the inline errors are displayed one time on the first div, two times on the second div, and so-forth. The alleviate this issue I’m now destroying the error element.

validator.resetForm();
$('label.error').remove();
Advertisements