Anonymous avatar Anonymous committed 303b6fa

[soc2009/model-validation] Minor edits to form validation docs.

Comments (0)

Files changed (1)

docs/ref/forms/validation.txt

 Most validation can be done using `validators`_ - simple helpers that can be
 reused easily. Validators are simple functions (or callables) that take a single
 argument and raise ``ValidationError`` on invalid input. Validators are run
-inside the ``run_validators`` method that is called from ``Field.clean`` once
-the value is validated by the field's methods.
+after the field's ``to_python`` and ``validate`` methods have been called.
 
 Validation of a Form is split into several steps, which can be customized or
 overridden:
       FloatField will turn the data into a Python ``float`` or raise a
       ``ValidationError``.
 
-    * Next step resides in ``validate()`` method. This is a method where all
-      field-specific validation, that cannot be abstracted into a validator,
-      should take place. It takes the value coerced to correct datatype and
-      raises ``ValidationError`` on any error. This method does not return
-      anything and shouldn't alter the value.
+    * The ``validate()`` method on a Field handles field-specific validation
+      that is not suitable for a validator, It takes the value coerced to
+      correct datatype and raises ``ValidationError`` on any error. This method
+      does not return anything and shouldn't alter the value. You should
+      override it to handle validation logic that you don't want to put in a
+      validator.
 
-    * Validators are run in the ``run_validators`` method. This method
-      aggregates all the errors from all validators run into a single
-      ``ValidationError``.
+    * The ``run_validators()`` method on a Field runs all of the field's
+      validators and aggregates all the errors into a single
+      ``ValidationError``. You shouldn't need to override this method.
 
     * The ``clean()`` method on a Field subclass. This is responsible for
       running ``to_python``, ``validate`` and ``run_validators`` in the correct
         def to_python(self, value):
             "Normalize data to a list of strings."
 
-            # return empty list on empty input
-            if not value: return []
-
+            # Return an empty list if no input was given.
+            if not value:
+                return []
             return value.split(',')
 
         def validate(self, value):
             "Check if value consists only of valid emails."
 
-            # check if value is given if the field is required
+            # Use the parent's handling of required fields, etc.
             super(MultiEmailField, self).validate(value)
 
             for email in value:
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.