Setting jQuery validation messages option to another map
I've got the rules defined below for a page:
$(document).ready(function() {
$.validator.setDefaults({
submitHandler : function() { alert("submitted!"); }
});
$("#prospectForm").validate({
errorLabelContainer : $("#errorDiv ul"),
wrapper : "li",
debug : true,
rules : {
prospectName : {
required : true,
rangelength : [2, 45]
},
groupSize : {
required : true,
digits : true
},
zipCode : {
required : true,
digits : true,
rangelength : [5, 5]
},
sicCode : {
required : true,
rangelength : [4, 4],
digits : true
},
agencyProducer : {
required : true
}
},
messages : errorMap
});
});
I defined errorMap like the following:
var errorMap = {
prospectName : {
required : "An entry is required in field Prospect.",
rangelength : "Prospect Name must be between 2 and 45 characters."
},
groupSize : {
required : "An entry is required in field Group Size.",
digits : "Numeric data is required in field Group Size."
},
zipCode : {
required : "An entry is required in field Zip Code.",
d开发者_JS百科igits : "Numeric data is required in field Zip Code.",
rangelength : "Zip Code must be 5 digits."
},
sicCode : {
required : "This is an invalid SIC code. Enter the SIC again or search for the SIC code.",
rangelength : "This is an invalid SIC code. Enter the SIC again or search for the SIC code.",
digits : "This is an invalid SIC code. Enter the SIC again or search for the SIC code."
},
agencyProducer : {
required : "An entry is required in the Agent field."
}
};
When I run this, I get errorMap undefined. I am including the errorMap definition code in a separate .js file and including this errorMsgDefs.js inside the html file after I include the jQuery and jQuery.validate files.
Any ideas? The docs say you can use a map for the value of the messages option, so what am I doing wrong?
Thanks for any help.
it sounds to me like its either not loading or its out of scope try making it global by remove the "var" before errorMap = and see if that fixes the problem
精彩评论