Dan G. Switzer, II schrieb:
Jörn,

This would make field2 required only if field1 is blank:

rules: {
 field2: { required: "#field1:blank" }
}

But I can't express that either field1 or field2 is required. How would
I express that using pre/post-condition and implies?

I was thinking about this the other day, and I was thinking maybe the best
way to do this might be to allow a function to be declared.

rules: {
        field2: { required: function(field){ return (condition); }
}

This would at least add a lot of flexibility for how a field could be
defined. It might also be interested to have a "generic" (or "function")
rule which you can use to define a really form specific throw away
validation method.
You can do that already. After implementing the suppurt for expressions, support for plain functions was really easy. I can imagine adding a method on the fly:

rules: {
        field2: function() { return condition; }
}

You couldn't define a default message, but that would be no problem, because you can add it to the messages option.
However, one of the problems mapping a rule to a specific form field is it
still doesn't do a could job with either/or rules (i.e. either Field1 or
Field2 must be filled in.) Where do you throw the error message? Which field
do you attach the field to?

This is where having an API is a little more handle, because you really need
to write a customized validation rule and you probably want to handle error
throwing in a very specific way.

This is where exposing a way to hook into the onValidate event and having
ways to throw an error message programmatically would be handy.
In general I agree. A hook could help a lot.
But whenever I stumble about an example like this I try to find a different approach. Because when I can't figure a good way to validate that, how is the user supposed to figure what to do? Isn't there a better way to get his correct input?

Maybe, maybe not. I like the approach map24.de is taking for entering addresses: There is one field to enter where you want to start, and another field to enter where you want to go to. You can search only for the start or for a route between both. The server checks its database against all know cities and streets and figures what is what. Ten times easier then filling out at least three fields for a single address.

--
Jörn Zaefferer

http://bassistance.de

Reply via email to