Brad
Brad

Reputation: 1691

Jquery Validate Script Error

This is a truly embarrasssing question. I am having a validate script problem and I have no idea why. Firebug tells me jquery is loaded, validation.js is loaded, Jquery UI is loaded and all is well. The script is on a included js page and is loaded.(does the same thing if the script in on the php file or included. Jquery 1.6.4

The error I get from firebug is: missing } after property list post:{

The } is obviously there. I can find nothing ebfore it or after that would cause this problem. The script looks picture perfect to me.

$(function(){             
  $("#postform").validate({
    rules: {
        title:{
            required: true,
            minlength: 8,
            maxlength: 200
        }
        post:{
            required: true,
            minlength: 35
        }
        category: {
            required: true
        }

        date:{
            date: true,
            required: true
        }
        author: {
            required: true,
            minlength: 6,   
            maxlength: 35
        }
    },          
    messages:{
        title:{
            required: "Required input",
            minlength: jQuery.format("At least {8} characters are necessary"),
            maxlength: jQuery.format("No more than {200} characters")
        }
        post:{
            required: "Required input",
            minlength: jQuery.format("At least {35} characters are necessary")
        }
        category: "Please choose a value from the dropdown",

        date: "A date is required",

        author: {
            required: "this field is required",
            maxlength: jQuery.format("No more than {36} characters"),
            minlength: jQuery.format("At least {5} characters are necessary")
        }

    }
});        
});

I am using ajax to process the form but it seems to me validate comes first so that shouldn't matter. I know that works.

I will also say, that I had a different set up before this (add rules on each name), the form would validate but still post to the DB even with invalid fields invalid.

Any thoughts? I have been on this for 2 days. Hopefully someone has seen this before

Upvotes: 0

Views: 222

Answers (2)

Sparky
Sparky

Reputation: 98718

You are missing a bunch of commas , exactly as follows....

  $("#postform").validate({
    rules: {
        title:{
            required: true,
            minlength: 8,
            maxlength: 200
        },
        post:{
            required: true,
            minlength: 35
        },
        category: {
            required: true
        },

        date:{
            date: true,
            required: true
        },
        author: {
            required: true,
            minlength: 6,   
            maxlength: 35
        }
    },          
    messages:{
        title:{
            required: "Required input",
            minlength: jQuery.format("At least {8} characters are necessary"),
            maxlength: jQuery.format("No more than {200} characters")
        },
        post:{
            required: "Required input",
            minlength: jQuery.format("At least {35} characters are necessary")
        },
        category: "Please choose a value from the dropdown",

        date: "A date is required",

        author: {
            required: "this field is required",
            maxlength: jQuery.format("No more than {36} characters"),
            minlength: jQuery.format("At least {5} characters are necessary")
        }
    }
  });   

Upvotes: 1

Alon Eitan
Alon Eitan

Reputation: 12025

fix like this example:

   title:{
        required: true,
        minlength: 8,
        maxlength: 200
    }***,***
    post:{
        required: true,
        minlength: 35
    }

Upvotes: 1

Related Questions