From 4ae746b574a84e30a8be4f207c9f386fa09c03f9 Mon Sep 17 00:00:00 2001 From: Jacob Kaplan-Moss Date: Sun, 31 Aug 2008 20:10:50 +0000 Subject: 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 --- docs/ref/forms/fields.txt | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'docs/ref/forms') 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`` ~~~~~~~~~~~~~ -- cgit v1.3