ram
ram

Reputation: 21

Jquery validate allows form submit even if there are errors

Jquery .validate function not working properly.

For the very first time on page load, if the submit button is clicked, nothing is being validated, even though the form inputs are empty. The form gets submitted even though the validate function is called in $(document).ready(function())

i have a form where all the input types are defined in a div name e.g., 'targetListDiv'

$("#saveTargetList").on('click', function(e) {

if (!$("#targetListDiv").validate()) { // Not Valid
            return false;
        } 
$.ajax({

    url : 'example.htm',
    type: 'POST',
    contentType: "application/json; charset=utf-8",
    dataType : 'json',
    data: JSON.stringify(data),
    success: function (text) { 

               alert(text);
            }, error: function(text){

                alert(text);
  });

always the form gets submitted even if there is an error.

No errors are being displayed to the customer. But if i click on a text box and lets say, the min length is 7, and i enter only 5 characters, then the error is being displayed.

Please let me know if there is a way to prevent this.

Thanks.

Upvotes: 0

Views: 2269

Answers (1)

ram
ram

Reputation: 21

I had missed the "name" attribute in input fields hence the validate function was not working properly.

including the "name" attribute resolved the issue.

Thanks guys!

Upvotes: 1

Related Questions