summaryrefslogtreecommitdiff
path: root/docs/ref/forms
diff options
context:
space:
mode:
authorJacob Kaplan-Moss <jacob@jacobian.org>2008-08-31 20:10:50 +0000
committerJacob Kaplan-Moss <jacob@jacobian.org>2008-08-31 20:10:50 +0000
commit4ae746b574a84e30a8be4f207c9f386fa09c03f9 (patch)
tree5b77386f6a88c6d4bfcea16829b418f259e66b55 /docs/ref/forms
parent3e71a684b35066285034f05efed5bb83dc1cf644 (diff)
Added a `TypedChoiceField` which acts just like `ChoiceField`, except that it
returns a value coerced by some provided function. Refs #6967. git-svn-id: http://code.djangoproject.com/svn/django/trunk@8771 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'docs/ref/forms')
-rw-r--r--docs/ref/forms/fields.txt27
1 files changed, 27 insertions, 0 deletions
diff --git a/docs/ref/forms/fields.txt b/docs/ref/forms/fields.txt
index 7654300617..262538fec7 100644
--- a/docs/ref/forms/fields.txt
+++ b/docs/ref/forms/fields.txt
@@ -362,6 +362,33 @@ Takes one extra required argument:
An iterable (e.g., a list or tuple) of 2-tuples to use as choices for this
field.
+
+``TypedChoiceField``
+~~~~~~~~~~~~~~~~~~~~
+
+.. class:: TypedChoiceField(**kwargs)
+
+Just like a :class:`ChoiceField`, except :class:`TypedChoiceField` takes an
+extra ``coerce`` argument.
+
+ * Default widget: ``Select``
+ * Empty value: Whatever you've given as ``empty_value``
+ * Normalizes to: the value returned by the ``coerce`` argument.
+ * Validates that the given value exists in the list of choices.
+ * Error message keys: ``required``, ``invalid_choice``
+
+Takes extra arguments:
+
+.. attribute:: TypedChoiceField.coerce
+
+ A function that takes one argument and returns a coerced value. Examples
+ include the built-in ``int``, ``float``, ``bool`` and other types. Defaults
+ to an identity function.
+
+.. attribute:: TypedChoiceField.empty_value
+
+ The value to use to represent "empty." Defaults to the empty string;
+ ``None`` is another common choice here.
``DateField``
~~~~~~~~~~~~~