Jquery validate or validate
I am using http://bassistance.de/jquery-plugins/jquery-plugin-validation/ a plugin followed by a pseudo-block I need to fix:
jQuery("#SearchForm").validate({
rules: {
Company: "required",
CompanyName: {
regex: "[a-zA-Z]*",
required: true,
minlength: 2
}
},
messages: {
Company: "Type required.",
CompanyName: "Only A-Z Allowed in the name."
},
errorPlacement: function(error, element) {
error.appendTo('#JsErrorMsg');
}
});
basically i have 1 text input type and 1 selection, i want to check if this is or can be used, but at least 1 must be used, if textbox is used, it should only accept characters to search by name field, another list selection is 1 list of company IDs. I hope this plugin is built, if it exists, before I grow and use the same styles it uses. it would seem strange if this library cannot do this.
Thank you for your help, greetings
you need to write a custom function to check that any one of the inputs is selected and put that as a callback
http://docs.jquery.com/Plugins/Validation/Methods/required#dependency-callback
I'm going to throw credit to @zod, but I wanted to post the final js for everyone to see. help others in the community.
jQuery("#SearchForm").validate({
rules: {
MallMgmtCompanyID: {
required: true
},
parent: {
required: function(element) {
if(jQuery("#MallName").length < 3 && jQuery("#MallMgmtCompanyID").val() === ""){
return false;
}
}
}
},
messages: {
MallMgmtCompanyID: "3 Characters or Company Selected are Required."
},
success: function() {
jQuery('#JsErrorMsg').remove();
UpdateSearch();
},
errorPlacement: function(error, element) {
error.appendTo('#JsErrorMsg');
}
});
jQuery("#searchbutton").click(function(){
jQuery("#SearchForm").valid();
});