Reputation: 6518
I am using Unobtrusive validation with ASP.NET MVC3. The field validation is working fine however I need to clear an error on a field through code without removing the fields ability to still validate.
E.g. a user enters a value which is incorrect which displays and error message, they click a button which clears the error message. The user enters another incorrect value and the error message shows again.
I can only find a method to reset the whole form, not an individual fields
Upvotes: 2
Views: 1389
Reputation: 12440
This is definitively a hack, but it will work:
(function($, global) {
global.hideError = function(selector) {
if(!selector) throw 'Arugment cannot be null or undefined : "selector"';
$(selector).removeClass('input-validation-error').next('span.field-validation-error').find('span').remove();
};
})(jQuery, window);
//Use it like so
hideError('#Password');
Upvotes: 1