Jquery Validation Plugin, dynamic form validation

前端 未结 2 636
萌比男神i
萌比男神i 2021-01-21 12:08

I\'m using the Jquery Validation Plugin to forms loaded via Ajax (dynamic forms). I know that as of Jquery 1.4, live events on submit is now possible. Now the problem is I want

相关标签:
2条回答
  • 2021-01-21 12:41

    Somehow this seems to work:

    $('.dynamicForm').live('mouseover',function(){
        $(this).validate({
            submitHandler:function(form){
                if(confirm("Are you sure?")){
                    form.submit();
                }
            }
        });
    });
    
    0 讨论(0)
  • 2021-01-21 13:01

    Use the submitHandler function available in the validate options:

    $(".dynamicForm").validate({
       submitHandler: function(form) { //Only runs when valid
         if(confirm('Are you sure?'))
           form.submit();
       }
    })
    

    From the docs - submitHandler:

    Callback for handling the actual submit when the form is valid. Gets the form as the only argument. Replaces the default submit. The right place to submit a form via Ajax after it validated.

    0 讨论(0)
提交回复
热议问题