Ticket #10361: 10361.diff

File 10361.diff, 2.6 KB (added by Tim Graham, 15 years ago)

ComboField and MultiValueField

  • docs/ref/forms/fields.txt

     
    680680
    681681Takes the following optional arguments:
    682682
    683 
    684683.. attribute:: URLField.max_length
    685684.. attribute:: URLField.min_length
    686685
     
    699698Slightly complex built-in ``Field`` classes
    700699-------------------------------------------
    701700
    702 The following are not yet documented.
    703 
    704701.. class:: ComboField(**kwargs)
    705702
     703    * Default widget: ``TextInput``
     704    * Empty value: ``''`` (an empty string)
     705    * Normalizes to: A Unicode object.
     706    * Validates that the given value against each of the fields specified
     707      as an argument to the ``ComboField``.
     708    * Error message keys: ``required``, ``invalid``
     709
     710Takes one extra required argument:
     711
     712.. attribute:: ComboField.fields
     713
     714The list of fields that should be used to validate the field's value (in the
     715order in which they are provided).
     716   
     717    >>> f = ComboField(fields=[CharField(max_length=20), EmailField()])
     718    >>> f.clean('test@example.com')
     719    u'test@example.com'
     720    >>> f.clean('longemailaddress@example.com')
     721    Traceback (most recent call last):
     722    ...
     723    ValidationError: [u'Ensure this value has at most 20 characters (it has 28).']
     724
    706725.. class:: MultiValueField(**kwargs)
    707726
     727    * Default widget: ``TextInput``
     728    * Empty value: ``''`` (an empty string)
     729    * Normalizes to: the type returned by the ``compress`` method of the subclass.
     730    * Validates that the given value against each of the fields specified
     731      as an argument to the ``MultiValueField``.
     732    * Error message keys: ``required``, ``invalid``
     733
     734    This abstract field (must be subclassed) aggregates the logic of multiple
     735    fields. Subclasses should not have to implement clean(). Instead, they must
     736    implement compress(), which takes a list of valid values and returns a
     737    "compressed" version of those values -- a single value.  For example,
     738    :class:`SplitDateTimeField` is a subclass which combines a time field and
     739    a date field into a datetime object.
     740
     741Takes one extra required argument:
     742
     743.. attribute:: MultiValueField.fields   
     744
     745A list of fields which are cleaned into a single field. Each value in ``clean``
     746is cleaned by the corresponding field in ``fields`` -- the first value is
     747cleaned by the first field, the second value is cleaned by thesecond field, etc.
     748Once all fields are cleaned, the list of clean values is"compressed" into a
     749single value.
     750
    708751.. class:: SplitDateTimeField(**kwargs)
    709752
    710753    * Default widget: ``SplitDateTimeWidget``
Back to Top