erichexter / twitter.bootstrap.mvc

nuget package to make bootstrap easy with mvc4
Apache License 2.0
248 stars 134 forks source link

Do not use a custom unobrusive validation script #91

Open fsateler opened 11 years ago

fsateler commented 11 years ago

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 commented 10 years ago

Seconded. This approach works much better.