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:
- Common field 1 [textbox1]
- Common field 2 [textbox2]
- Common field 3 [textbox3]
- Account type:
- [radio] Buyer //buyerForm.show()
- [radio] Seller //sellerForm.show()
- <div id="buyerForm">
- Specific field: [textbox4]
- Specific field: [textbox5]
- </div>
- <div id="sellerForm">
- Specific field: [textbox6]
- Specific field: [textbox7]
- Specific field: [checkbox8]
- </div>
- 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:
- $("#signupform").validate({ /*... rules to validate common fields ... */ })
- if($("#radio").val()=="buyer")
- {
- $("#signupform").validate({ /*... rules to validate buyer fields ... */ })
- }
- else
- {
- $("#signupform").validate({ /*... rules to validate seller fields ... */ })
- }
But is seem that only my common fields get validated.
How should I handle that situation ?
Thanks.