2

On one form I have City, State, ZIP code on one line in the form (inside one block element).

My error div for the validate plugin slides nicely under the form div so that message is contextual.

Is there a way to combine a rule so that it's not 3 separate validation rules? In other words, if city is blank, or state is blank, or ZIP is blank, I want to trigger just one error message div "City, State and ZIP code are required". Likewise if 2 of 3 or 3 of 3 are blank I still want to have just one error div returned by validate.

1 Answer 1

2

You can make use of the groups and errorPlacement option to your needs. For example (taken from http://docs.jquery.com/Plugins/Validation/validate):

$("#myform").validate({
  groups: {
    username: "fname lname"
  },
  errorPlacement: function(error, element) {
     if (element.attr("name") == "fname" 
                 || element.attr("name") == "lname" )
       error.insertAfter("#lastname");
     else
       error.insertAfter(element);
   },
   debug:true
 });
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.