Skip to content

Commit

Permalink
copy extra_validators to avoid mutation
Browse files Browse the repository at this point in the history
document extra_validators
  • Loading branch information
davidism committed Apr 22, 2020
1 parent 8d0f078 commit fcf40a0
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions wtforms/form.py
Expand Up @@ -293,13 +293,25 @@ def __delattr__(self, name):
super(Form, self).__delattr__(name)

def validate(self, extra_validators=None):
"""Validate the form by calling ``validate`` on each field.
Returns ``True`` if validation passes.
If the form defines a ``validate_<fieldname>`` method, it is
appended as an extra validator for the field's ``validate``.
:param extra_validators: A dict mapping field names to lists of
extra validator methods to run. Extra validators run after
validators passed when creating the field. If the form has
``validate_<fieldname>``, it is the last extra validator.
"""
Validates the form by calling `validate` on each field, passing any
extra `Form.validate_<fieldname>` validators to the field validator.
"""
extra = extra_validators or {}
if extra_validators is not None:
extra = dict(extra_validators)
else:
extra = {}

for name in self._fields:
inline = getattr(self.__class__, 'validate_%s' % name, None)

if inline is not None:
extra.setdefault(name, []).append(inline)

Expand Down

0 comments on commit fcf40a0

Please sign in to comment.