Can JQuery.Validate plugin prevent submission of an Ajax form

后端 未结 7 1785
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-02-02 15:00

I am using the JQuery form plugin (http://malsup.com/jquery/form/) to handle the ajax submission of a form. I also have JQuery.Validate (http://docs.jquery.com/Plugins/Validatio

7条回答
  •  北海茫月
    2021-02-02 15:42

    You need to add a callback function for use with the beforeSubmit event when initializing the ajaxForm():

    var options = {
            beforeSubmit: function() {
                return $('#searchForm').validate().form();
            },
            target: '#detailsView'
        };
    

    Now it knows to check the result of the validation before it will submit the page.

提交回复
热议问题