I’ve been struggling to reset a form within a dialog window upon close. My form is using jQuery validate and I’ve tried to use the documented resetForm() function, but no luck.
Below are two attempts on how I am trying to achieve clearing the form upon the user hitting “Close”. Neither are working.
Here’s the jsFiddle: http://jsfiddle.net/FjT7T/6/
$("#myDialog").dialog({
autoOpen: false,
close: function(event, ui) {
// Attempt to reset the form using JQuery validates resetForm(), not working.
var validator = $("#myForm").validate();
validator.resetForm();
// Attempt to reset the form and remove the error classes, not working either.
$(this).closest("form")[0].reset().removeClass("error");
}
});
Have you tried plain javascript reset?
Or even jQuery, but with the form’s id:
And to remove the class, why note use the
#id