Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Descibe the ANY_OF validator. #368

Merged
merged 1 commit into from
Oct 19, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion sources/29-web2py-english/07.markmin
Original file line number Diff line number Diff line change
Expand Up @@ -2267,14 +2267,35 @@ On success, the ``__call__`` method reads a date string from the form and conver
01/01/2008
``:code

When multiple validators are required (and stored in a list), they are executed in order and the output of one is passed as input to the next. The chain breaks when one of the validators fails.
#### Multiple Validators

Normally, when multiple validators are required (and stored in a list), they are executed in order and the output of one is passed as input to the next. The chain breaks when one of the validators fails.

Conversely, when we call the ``formatter`` method of a field, the formatters of the associated validators are also chained, but in reverse order.

------
Notice that as alternative to custom validators, you can also use the ``onvalidate`` argument of ``form.accepts(...)``, ``form.process(...)`` and ``form.validate(...)``.
------

As an alternative to the chained behavior described above,
the
``ANY_OF``:inxx validator can be used to combine a list of validators,
and to pass if **any** of the validators pass.
If none of the validators pass,
the error message returned will be that of the last validator in the
list.

``
>>> ANY_OF([IS_EMAIL(),IS_ALPHANUMERIC()])('[email protected]')
('[email protected]', None)
>>> ANY_OF([IS_EMAIL(),IS_ALPHANUMERIC()])('abco')
('abco', None)
>>> ANY_OF([IS_EMAIL(),IS_ALPHANUMERIC()])('@ab.co')
('@ab.co', 'enter only letters, numbers, and underscore')
>>> ANY_OF([IS_ALPHANUMERIC(),IS_EMAIL()])('@ab.co')
('@ab.co', 'enter a valid email address')
``:code


#### Validators with dependencies

Expand Down