Best approach for extending unobtrusive javascript in MVC3 to add a style to a div client side

后端 未结 7 854
情话喂你
情话喂你 2021-01-31 03:50

I\'m using html5/Razor/MVC3 leveraging the Bootstrap template from Twitter. I want to have form validation that looks slick like they\'ve documented (http://twitter.github.com/b

7条回答
  •  梦谈多话
    2021-01-31 04:09

    The $.validator.setDefaults method solved this issue for me with Bootstrap from Twitter. I'm usingjquery.validate.js and jquery.validate.unobtrusive.js.

    Since unobtrusive validation on DOM ready scans your document and caches unobtrusive validation options for each form it encounters, it is needed to call the $.validator.setDefaults method before document scan occurs.

    // setup defaults for $.validator outside domReady handler
    $.validator.setDefaults({
        highlight: function (element) {
            $(element).closest(".clearfix").addClass("error");
        },
        unhighlight: function (element) {
            $(element).closest(".clearfix").removeClass("error");
        }
    });
    
    $(document).ready(function() {
           // do other stuff
    });
    

提交回复
热议问题