Search code examples
jqueryjquery-uipseudocode

jquery validate either or with validate


I am using the http://bassistance.de/jquery-plugins/jquery-plugin-validation/ plug in with the follow pseudo block that 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 input type text and 1 select, I want to validate that either or can be used, but at least 1 must be used, if the text box is used, it should only accept characters to search on a name field, the other select list is a 1-x list of company ids. I am hoping to build off this plug in, if it exists, before growing my own and using the same styles it uses. it would seem odd if this library can not do this.

thank you for your help, cheers


Solution

  • you have to write a custom function to validate any one of the input is selected and put that as a call back

    http://docs.jquery.com/Plugins/Validation/Methods/required#dependency-callback