Dmitrii 'Mamut' Dimandt schrieb:
Jörn Zaefferer wrote:
Dmitrii 'Mamut' Dimandt schrieb:
Jörn Zaefferer wrote:
I'm gonna take a look at that library for some inspiration. And maybe
copy some validation methods (called rules at yav).

Let me know if you have any specific requests for the jQuery
validation plugin.

That would be the pre-condition, implies and post-condition. Those
definitely rule
That is an interesting concept that I'm currently trying to understand.

My plugin supports required-dependencies using expressions and
functions, but they have their limit.

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?

That I don't know :)

'implies' is best seen with the advanced form in the example
(http://yav.sourceforge.net/en/learnbyexample.html). See how validation
on the last input field changes depending on what's selected in the
combo box.

If you chose "email" the input is validated against one set of rules:

rules[15]='contactType|equal|phone|pre-condition';
rules[16]='contact|regexp|^[0-9]{10}$|post-condition';
rules[17]='15|implies|16|Enter a phone (ten digits)

So if contactType value changes to phone, contact is validated against
^[0-9]{10}$

However:

rules[18]='contactType|equal|e-mail|pre-condition';
rules[19]='contact|regexp|[EMAIL PROTECTED]|post-condition';
rules[20]='18|implies|19|Enter a valid e-mail'

If contactType becomes 'e-mail' contact is validated against [EMAIL PROTECTED]
Okay, I can't do that with my expressions. Gotta check how that can be implemented.
Same is with the 'Name required' checkbox. If the checkbox is checked,
you must input a name:

rules[11]='nameRequired|equal|checked|pre-condition';
rules[12]='name|required|post-condition';
rules[13]='11|implies|12|name required';
While that is easy:

name: { required: "#nameRequired:checked" }

Reuses both JavaScript and jQuery's expressions.
I guess what you want is something like:

rules[1]='field1|equal||pre-condition';
rules[2]='field2|regexp|^a-zA-Z$|post-condition';
rules[3]='1|implies|2|Enter either field 1 or field 2';

rules[4]='field2|equal||pre-condition';
rules[5]='field1|regexp|^a-zA-Z$|post-condition';
rules[6]='4|implies|5|Enter either field 1 or field 2';

Or some such. I'm not sure (I'm guessing from the examples, never used
the validator myself :) )
The problem is: How to prevent that the user simply fills out both fields?

--
Jörn Zaefferer

http://bassistance.de

Reply via email to