How to apply validation on Two Buttons

Mar 21, 2013 at 11:06 AM
Consider Case
I have 3 Textboxes and 2 Buttons Approve and Reject resp.
For Approve Button I have to check only 2Textboxes for RequireFiled bt for Reject I have to check 3Textboxes for RequireFiled.Then how can I achieve IT?
Coordinator
Mar 22, 2013 at 10:37 AM
Well you can have different validation groups on a page, e.g:
<input type="text" validate="group1" require="Please enter value" />
<input type="text" validate="group2" require="Please enter value" />

<input type="submit" value="Accept" onclick="return validate('group1');">
<input type="submit" value="Reject" onclick="return validate('group2');">
But if you want a textbox shared between 2 validation groups then you'll need to change the following jquery.validator.js code (change css selector to contains instead of equals):
$("*[validate=" + group + "]").each(function(i, elm) {
change to:
$("*[validate*=" + group + "]").each(function(i, elm) {
Then you can add multiple validation groups to a single textbox:
<input type="text" validate="group1 group2" require="Please enter value" />
<input type="text" validate="group2" require="Please enter value" />

<input type="submit" value="Accept" onclick="return validate('group1');">
<input type="submit" value="Reject" onclick="return validate('group2');">
With this change though 'group1' will also validate 'group12' fields since group12 text contains group1 so you'll just need to be aware.