I want to call a jquery function to manually remove errors from a single field and reset the error markup. Is there a function that does this that would be similar to the reset
This functionality is possible via focusCleanup: true
option and triggering focusin
event on desired element. But it is not always desirable to trigger this event. So apparently, you can use plugin’s internal code which is running on focusin
and invoke it externally like so:
/*get your element and containing validated form*/
var $that = $('#desired_elemenet');
var $form = $that.closest('form');
/*get validator object for the form*/
var validator = $form.validate();
/*use internal code of a plugin to clear the field*/
if (validator.settings.unhighlight) {
validator.settings.unhighlight.call( validator, $that[0], validator.settings.errorClass, validator.settings.validClass );
}
validator.hideThese( validator.errorsFor( $that[0] ) );
Can't find anything built in to the validation library but this hack works:
$('#email').removeClass('error').next('label.error').remove();
You can do the following to validate a single field:
$('#your_field').valid();
Maybe it will help someone :-)
Thanks!
this resets the entire form
var validator = $("#myform").validate();
validator.resetForm();
this will reset only the name
element
$("#skip").click(function() {
var rules = $("#name").removeAttrs("min max"); // remove min and max
$("#form").submit(); // submit, as there are no attributes, it will not have an error
$("#name").attr(rules); // add it again so you can validate it
});
you can use
$("#selector").removeClass("error");
$("#selector-error").remove();
var form = $('#form');
var validator = form.validate();
// Validate single field from that form.
var myfield = $('#myfield');
myfield.removeData('previousValue').removeAttr('aria-invalid');
validator.resetElements(myfield);