i am using validation plugin to validate a form, here are my rules
$("#creatProfileForm").validate({
ignore: [], //use for hidden fields validation, by default hidden fields are ignored
rules : {
"firstName" : {
required : true,
},
"lastName" : {
required : true,
},
"gender" : {
required : true,
},
"password" : {
required : function(element) {
if($("#isSocialSignup").val() == "true" || $("#isSocialSignup").val() == true)
return true;
},
minLength : 6
}
},
messages : {
"firstName" : {
required : 'First Name is required',
},
"lastName" : {
required: "Last Name is required",
},
"gender" : {
required : "Gender is required",
},
"password" : {
required : "Password is required",
minLength : "Lenght should be atleast 6 characters"
}
},
errorPlacement: function(error, element) { //custom location for error placement
if (element.attr("name") == "gender") {
error.insertAfter(".temp");
} else {
error.insertAfter(element);
}
}
});
UPDATE : if i remove the call back function and add "required:true", it works.
My problem is with password field, I have stored a Boolean value in view and using that value i am deciding the required for password field. If value is true, password is required else not required.
When i submit the form, on console i get "false" printed , but still password field also show message, "password is required"
What is wrong with my code. Kindly help me. thanks in advance
minlength
rule incorrectly. – Sparky