jQuery using .on and .validate must submit form twice to validate

前端 未结 5 1415
走了就别回头了
走了就别回头了 2020-12-12 04:09

I am loading a form via ajax and usind the new .on() to load the jQuery validate plugin is not loaded before I press the submit a second time. I understand why I think. The

5条回答
  •  不知归路
    2020-12-12 04:56

    You need to add a selector in the call to on to make a delegate instead of a regular bind:

    $(document).on("submit", "#myform" function(event){
      $(this).validate();
      event.preventDefault();
    });
    

    If possible, bind the delegate to an element closer to the form than the entire document.

提交回复
热议问题