How to add a 'submitHandler' function when using jQuery Unobtrusive Validation?

前端 未结 5 2010
-上瘾入骨i
-上瘾入骨i 2020-11-27 13:31

I\'m validating a form using the new unobtrusive validation features in ASP.NET MVC 3.

So there is no code that I have written to setup jQuery validate to start vali

5条回答
  •  忘掉有多难
    2020-11-27 14:19

    I prefer to inject an event handler, so that it can be bound to... :)

    //somewhere in your global scripts
    $("form").data("validator").settings.submitHandler = function (form) {
        var ret = $(form).trigger('before-submit');
        if (ret !== false) form.submit();
    };

    This way, I can bind to it anywhere needed...

    //in your view script(s)
    $("form").bind("before-submit", function() {
        return confirm("Are you sure?");
    });

提交回复
热议问题