Using JQuery Validate Plugin to validate multiple form fields with identical names

Instead of changing the source file jquery.validation you can simply override the function you need to edit only in the pages that requires it. An example would be: $.validator.prototype.checkForm = function() { //overriden in a specific page this.prepareForm(); for (var i = 0, elements = (this.currentElements = this.elements()); elements[i]; i++) { if (this.findByName(elements[i].name).length !== undefined …

Read more

Jquery Validate custom error message location

What you should use is the errorLabelContainer jQuery(function($) { var validator = $(‘#form’).validate({ rules: { first: { required: true }, second: { required: true } }, messages: {}, errorElement : ‘div’, errorLabelContainer: ‘.errorTxt’ }); }); .errorTxt{ border: 1px solid red; min-height: 20px; } <script type=”text/javascript” src=”http://code.jquery.com/jquery-1.11.1.js”></script> <script type=”text/javascript” src=”http://cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.12.0/jquery.validate.js”></script> <script type=”text/javascript” src=”http://cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.12.0/additional-methods.js”></script> <form id=”form” method=”post” …

Read more

jQuery Form Validation before Ajax submit

You could use the submitHandler option. Basically put the $.ajax call inside this handler, i.e. invert it with the validation setup logic. $(‘#form’).validate({ … your validation rules come here, submitHandler: function(form) { $.ajax({ url: form.action, type: form.method, data: $(form).serialize(), success: function(response) { $(‘#answers’).html(response); } }); } }); The jQuery.validate plugin will invoke the submit handler …

Read more