I’m using a jquery validation plugin
First I add the validation to the form:
$('#EmployeeForm').validate({
rules: {
"Employee.FirstName": "required",
"Employee.PatronymicName": "required",
"Employee.LastName": "required",
"Employee.BirthDay": { required: true, date: true }
},
messages: {
"Employee.FirstName": { required: "*" },
"Employee.PatronymicName": { required: "*" },
"Employee.LastName": { required: "*" },
"Employee.BirthDay": { required: "*", date: "00.00.00 format" }
}
});
It works fine until here. I then later a need to add validation rules to other form elements:
$('#Address_A.Phone1, #Address_A.Phone2, #Address_B.Phone1, #Address_B.Phone2')
.rules("add", {
digits: true
});
Here I get an error: ‘form’ is null or not an object
I check, the form and all the elements in it are created before I add validation to it.
I cant figure out what’s wrong.
Just a guess is
Address_A.Phone1the id of your element?If yes I guess your problems comes from the fact that you use
.in your element id’s. But jQuery won’t understand e.g.#Address_A.Phone1as give me element with idAddress_A.Phone1but instead will interpret this selector as: Give me element with idAddress_Awhich has the classPhone1.But actually this doesn’t explain the error. Can you append on which line this error occurs. Is it in your code or inside the plugin code? If inside the plugin on which line