Validation; multiple validate() for a single form

Validation; multiple validate() for a single form

Hi,

I've many dynamic form on my current project. One if them have a two radio button, acting a little bit like tabs. If you select the first radio, the end of the form change to display the "branche #1", and if you select the second radio button, the end of the form change to display the "branche #2".

Let recap with dummy code:

  1. Common field 1 [textbox1]
  2. Common field 2 [textbox2]
  3. Common field 3 [textbox3]
  4. Account type:
  5. [radio] Buyer //buyerForm.show()
  6. [radio] Seller //sellerForm.show()
  7. <div id="buyerForm">
  8.      Specific field: [textbox4]
  9.      Specific field: [textbox5]
  10. </div>
  11. <div id="sellerForm">
  12.     Specific field: [textbox6]
  13.     Specific field: [textbox7]
  14.     Specific field: [checkbox8]
  15. </div>
  16. Common field: [checkbox9]

And now I will have to make 3 validations:
1) The first one for the common field.
2) The second one, if buyer is selected.
3) The third one, if seller is selected.

So the code should look like:
  1. $("#signupform").validate({ /*... rules to validate common fields ... */ })
  2. if($("#radio").val()=="buyer")
  3. {
  4.      $("#signupform").validate({ /*... rules to validate buyer fields ... */ })
  5. }
  6. else
  7. {
  8.     $("#signupform").validate({ /*... rules to validate seller fields ... */ })
  9. }
But is seem that only my common fields get validated.
How should I handle that situation ?

Thanks.