开发者

How to perform validation on submit only - jQuery Validation plugin

开发者 https://www.devze.com 2022-12-09 04:57 出处:网络
I want the jQuery Validate plugin to only display the validation messages only upon form submit and not when the focus from a input field is lost. How do Ii achieve this?

I want the jQuery Validate plugin to only display the validation messages only upon form submit and not when the focus from a input field is lost. How do Ii achieve this?

Right now I am following this pattern, which leads to validation after lost focus event:

<html>
<head>
 <script>
  $(document).ready(function(){
    $("#commentForm").validate();
  });
  </script>

</head>
<body>
<form class="cmxform" id="commentForm" method="get" action="">
 <fieldset>
<p>
     <label for="cname">Name</label>
   开发者_如何学编程  <em>*</em><input id="cname" name="name" size="25" class="required" minlength="2" />
   </p>
</fieldset>
</form>
</body>
</html>


You need to disable all three handlers if you wish to receive absolutely no errors before submission and you can do validation like this:

$('#commentForm').validate({
    onfocusout: false,
    onkeyup: false,
    onclick: false
})


You have to change the default option for onfocusout

$(".selector").validate({
   onfocusout: false
})

More options to enable or disable are listed here - http://docs.jquery.com/Plugins/Validation/validate#toptions

0

精彩评论

暂无评论...
验证码 换一张
取 消