Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not use a custom unobrusive validation script #91

Open
fsateler opened this issue Apr 26, 2013 · 1 comment
Open

Do not use a custom unobrusive validation script #91

fsateler opened this issue Apr 26, 2013 · 1 comment

Comments

@fsateler
Copy link

There is no need to provide a script that may fall out of sync. jQuery.Validation provides a way to modify the behavior:

(function ($) {
    var defaults = $.validator.defaults,
        oldHighlight = defaults.highlight,
        oldUnhighlight = defaults.unhighlight;

    defaults.highlight = function (element, errorClass, validClass) {
        oldHighlight(element, errorClass, validClass);
        // Mark the parent controls as erroneous
        $(element).closest('.control-group').addClass('error');
    };

    validator.defaults.unhighlight = function (element, errorClass, validClass) {
        oldUnhighlight(element, errorClass, validClass);
        $(element).closest('.control-group').removeClass('error');
    };
})(jQuery);
@MattHoneycutt
Copy link

Seconded. This approach works much better.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants