validator plugin

validator plugin

i am getting a pretty typical error message that appears to appear for folks who have typos in their validator code blocks,

$.validator.methods[method] is undefined

i have spent most of the day going through my code, and comparing it to other working validation code i have in other pages, i have rewritten a bunch of stuff, and to no avail, i am still getting the same error so i figured i would try the community here, to see if the communal mind would see something, or have knowledge i do not.

i have my validator code in the document ready function,
i use addMethod to define 3 pieces i want to validate
i later use the add method to dynamically add validation to form fields (all form fields are built dynamically (and contained within tabs). i currently use the 'class' attribute in the form elements, so dont see an easy way to rebuild the application to utilize the inline ability via 'class'.
so, for some items that use built in validation methods (number()) work fine, it is just the piece that uses the validation pieces from addMethod.

heh, that sounds all kinda of confused, so here is some code:   









  1.         $j.validator.addMethod('chkMonth', function(value,element){
                var nd = new Date();            var s = $j(element).val();
                var y = s.substring(6,10)-0;     //cast year as a number
                var d = s.substring(3,5)-0;        //cast d as a number
                var m = s.substring(0,2)-1;        //javascript months run 0-11
                var ms = (new Date(y,m,d)).getTime();
                nd.setTime(ms);
               
                return (nd.getMonth()=== m);
            }, " ");

            $j.validator.addMethod('chkDay',function(value,element){
                var nd = new Date();
                var s = $j(element).val();
                var y = s.substring(6,10)-0;     // - 0 will cast as a number
                var d = s.substring(3,5)-0;        // - 0 will cast as a number
                var m = s.substring(0,2)-1;        //javascript months run 0-11
                var ms = (new Date(y,m,d)).getTime();
                nd.setTime(ms);
               
                return (nd.getDate()=== d);
            }, " ");

            $j.validator.addMethod('chkYear',function(value,element){
                var nd = new Date();
                var s = $j(element).val();
                var y = s.substring(6,10)-0;     //cast year as a number
                var d = s.substring(3,5)-0;        //cast d as a number
                var m = s.substring(0,2)-1;        //javascript months run 0-11
                var ms = (new Date(y,m,d)).getTime();
                nd.setTime(ms);
               
                return (nd.getFullYear()=== y);
            }, " ");
           
            $j("##frmAnswers").validate({
                focusCleanup: true,
                onfocusout: false,
                onkeyup: false,
                highlight: function(element, errorClass) {
                    $j('##'+$j(element).attr("id")).css("background-color", "f8ffa1");
                },
                unhighlight: function(element, errorClass) {
                    $j('##'+$j(element).attr("id")).css("background-color", "");
                },
                errorLabelContainer: "##errorMessage",
                wrapper: "li"
            });
               
















































this is the where i use the add:

  1.     function addValidationRules(){
            var $id;
            var $class;
            $j('input:text:visible').each(function(i,e){
                $id=$j(this).attr('id');
                $class=$j(this).attr('class');
                switch($class){
                    case '_date':
                        $j('##'+$id).rules("add",{
                            chkMonth: true,
                            chkDay: true,
                            chkYear: true,
                            messages:{
                                chkMonth: "Not a valid Month - be sure you are in MM/DD/YYYY format.",
                                chkDay: "Not a valid Day - be sure you are in MM/DD/YYYY format.",
                                chkYear: "Not a valid Year - be sure you are in MM/DD/YYYY format."
                            }
                        });
                    break;
                    case '_currency':
                        $j('##'+$id).rules("add",{
                            number:true,
                            messages:{
                                number:"Field must be numeric."
                            }
                        });
                    break;
                    case '_number':
                        $j('##'+$id).rules("add",{
                            number:true,
                            messages:{
                                number:"Field must be numeric."
                            }
                        });
                    break;
                    default:
                    // no default value
                    break;
                }
            });
        };












































the addValidationRules function is called from a function which is the event for a button click:

  1.     function saveAnswers(){
            addValidationRules();
           
            var isValid = $j('##frmAnswers').valid();
            if(isValid){
                var arrayID=[];
                var arrayTYPE=[];
                var arrayANSWER=[];
                var cntr = 0;
    ... }








so, as i mentioned, if i comment out the  _date case in the switch, the _currency and _number both work flawlessly, if i implement the _date case, i get the error.
i tried setting the rules inside the .validate() portion of the code, which was a no go.

on a side note about the code,
var $j = jQuery.noConflict(); is used on this page, thus the funky $j notation.
the double hash ## is because these are coldfusion files, and the second hash escapes the first.
all of the form elements are in tabs. it does not appear the tabs are populated when the $j(document).ready() event happens, and since they are dynamic pages that drive the tabs, i cant grab the coldfusion content of the tabs to dynamically populate the rules via coldfusion.

if i have to, i will rebuild my pages with each page behind the tabs each having their own forms, with their own validation objects, but i am hoping someone will point out something i have missed that is obvious, or where i am just ignorant about the validator and the way it needs to be implemented.


heh, this has ended up being a very long post.
i appreciate the views, comments and help.

thanks so much.