2

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

1 Answer 1

1

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');
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.