jQuery Validate not triggering -


i have following html , js, not triggering jquery.validate validation on text input field blur or form submit. if add "required" attribute directly text input field, default error message kicks in instead. can please me figure out why below not work?

<!doctype html> <html> <head> <script type="text/javascript" src="jquery.js"></script> <script type="text/javascript" src="jquery.validate.min.js"></script> <script type="text/javascript" src="jquery.validate.unobtrusive.min.js"></script>  </head> <body>     <form id="test" action="test.html" method="post">         <input type="text" name="txtname" />             <input type="submit" name="btnsubmit" />     </form> </body> </html> <script type="text/javascript">     $(document).ready(function(){         validateform();      });      function validateform(){         $.validator.unobtrusive.parse($("form"));          $('#test').validate({             rules: {                 "txtname": "required"             },             messages: {                 "txtname": "this name required sure!"             },             errorplacement: function (error, element) {                 $(element).parent().append(error);             },             onfocusout: function (element) { this.element(element); }         });     } </script> 

<script type="text/javascript" src="jquery.validate.unobtrusive.min.js"></script> 

why including unobtrusive plugin?

you cannot simultaneously use unobstrusive plugin while calling .validate() method yourself.

why?

because unobtrusive plugin automatically constructs , calls .validate() method based on html attributes.

since plugin uses first call .validate() initialize validation, automatically ignores subsequent calls. call .validate() totally ignored.

if add "required" directly text input field, default error message kicks in instead.

because of unobtrusive plugin, call .validate() totally ignored jquery validate. why works when put required attribute within input element.

completely remove unobtrusive plugin , works fine:

http://jsfiddle.net/ocx864nu/


Comments

Popular posts from this blog

python - TypeError: start must be a integer -

c# - DevExpress RepositoryItemComboBox BackColor property ignored -

django - Creating multiple model instances in DRF3 -