Dan G. Switzer, II schrieb:
Aaron,

I may be misunderstanding something, but what does this do that
$.validator.addMethod[1] doesn't?

The addMethod would accomplish the same thing. The addMethod() is really
affective for building a library of reusable validation method.

However, there are times when you have very specific, non-reusable rules you
need to implement. For these cases, being able to just define a rule inline
makes a lot of sense.
Also, the original discussion came from how to validate either/or type
validation rules and I was just trying to think of ways you might easily
build a rule to do that.
I like the idea.Gonna test if that works out.

About the xor-validation, I wonder if this could work:

$.validator.addMethod('xor', function(value, element, parameter) {
        return value && $(parameter).is(":blank");
});

rules: {
        field1: { xor: "#field2" },
        field2: { xor: "#field1" }
},
messages: {
        field1: "Please specify either field1 or field2",
        field2: "Please specify either field1 or field2"
}

If both are empty, both are invalid. If both have a value, both are invalid. Whats left are two valid combinations. Am I missing something, apart from trying it out?

--
Jörn Zaefferer

http://bassistance.de

Reply via email to