Skip to content

Commit

Permalink
Descibe the ANY_OF validator.
Browse files Browse the repository at this point in the history
(See issue web2py#366)
  • Loading branch information
snidelytoo committed Aug 16, 2017
1 parent f288f41 commit 386be76
Showing 1 changed file with 22 additions and 1 deletion.
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

0 comments on commit 386be76

Please sign in to comment.