views:

1611

answers:

2

I am using JQuery Validation plugin and have a question about validation. If I have 3 text fields on a form, textboxA, textboxB, and textboxC. I need to make textboxA and textboxB are required to Save, but I want to alert textboxC was not filled in.

For example: textboxA and textboxB have data and the form is submitted, an alert to the user would state that textboxC was not filled out, do you wish to continue. If the user clicks yes, then the form saves.

On the other hand, if textboxA and textboxB are filled in and textboxB is blank. This would alert on submit that you cannot Save since textboxB is not filled in.

Thanks

A: 

Why not just leave the 'save' button disabled, unless textboxA and textboxB are not empty.

When the button is enabled after the two required fields have been filled in, check if 'C' is empty, and if so, call the confirm('Are you sure, C is not filled in etc').

I would suggest using this method, with a message in the page telling the user that A and B are required, and C is optional, instead of waiting for the user to choke and giving him popup error messages.

karim79
xanadont
A: 

I would try a custom validation, where your valdation function will look like:

$.validator.addMethod("textboxC_validation", function(value) {
    return confirm('Are you sure you dont want to enter something in textboxC?');
}, 'Please enter something in textboxC!');

and then set it as the rule for your input:

rules: {
    textboxC: "textboxC_validation",
}

I've done something similar before, but the above is untested

Adam