Suppressing xVal in certain instances

Apr 22, 2010 at 4:14 PM
Edited Apr 22, 2010 at 4:17 PM

I have two scenarios which i think will probably be solved in different ways. I've had a google/look on here, but not found anything that solves the problems

 

1) I have a page with 3 buttons, each button submits to a different action (Think of each button submitting a change for its group). The page uses one model and form.

If i click on button A, the validation is kicked in for button B and C's textboxes, which i dont want to happen.

 

2) I have a page that displays several textboxes dependent on what the user clicks (Radio buttons). So if they click section B, a few more textboxes are displayed. This page is setup in the same way as the first (One model and form), but uses an ajax call instead of a normal http post.

The problem is, i only want to validate the textboxes which are visible, thus if the user clicks section A, section B and C's textboxes should not be validated.

 

Any ideas?

PS. I am using jQuery Validation, and i know this question is to do more with jQuery then xVal since i want the behavior to be client side.

 

Apr 22, 2010 at 4:59 PM

Problem 2 fixed : http://stackoverflow.com/questions/1316602/advanced-jquery-validation-avoiding-validations-on-certain-conditions/1316818#1316818

 

I changed "_attachRuleToDOMElement" in "xVal.jquery.validate.js"

 

BEFORE: 

 switch (ruleName) {
                case "Required":
                    options.required = true;
                    options.messages = { required: errorText || xVal.Messages.Required };
                    break;

AFTER:

switch (ruleName) {
                case "Required":
                    options.required = '#' + element.attr('id') + ':visible';  //true;
                    options.messages = { required: errorText || xVal.Messages.Required };
                    break;