summaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authorMalcolm Tredinnick <malcolm.tredinnick@gmail.com>2006-09-22 12:46:35 +0000
committerMalcolm Tredinnick <malcolm.tredinnick@gmail.com>2006-09-22 12:46:35 +0000
commit4ca66711b5438bcab6309e9e331eeb1bd9e2b63d (patch)
tree4ddc4020afa8f6b904b65f006892b862cd6ded72 /docs
parentc3d7aad6d0911bb84120d7c8d41923c895784b21 (diff)
Documented the always_test attribute for validator functions.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@3792 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'docs')
-rw-r--r--docs/forms.txt27
1 files changed, 27 insertions, 0 deletions
diff --git a/docs/forms.txt b/docs/forms.txt
index 0d492ad7ee..0ffb0bdcb7 100644
--- a/docs/forms.txt
+++ b/docs/forms.txt
@@ -481,6 +481,33 @@ the data being validated.
Also, because consistency in user interfaces is important, we strongly urge you
to put punctuation at the end of your validation messages.
+When Are Validators Called?
+---------------------------
+
+After a form has been submitted, Django first checks to see that all the
+required fields are present and non-empty. For each field that passes that
+test *and if the form submission contained data* for that field, all the
+validators for that field are called in turn. The emphasised portion in the
+last sentence is important: if a form field is not submitted (because it
+contains no data -- which is normal HTML behaviour), the validators are not
+run against the field.
+
+This feature is particularly important for models using
+``models.BooleanField`` or custom manipulators using things like
+``forms.CheckBoxField``. If the checkbox is not selected, it will not
+contribute to the form submission.
+
+If you would like your validator to *always* run, regardless of whether the
+field it is attached to contains any data, set the ``always_test`` attribute
+on the validator function. For example::
+
+ def my_custom_validator(field_data, all_data):
+ # ...
+
+ my_custom_validator.always_test = True
+
+This validator will always be executed for any field it is attached to.
+
Ready-made Validators
---------------------