~ubuntu-branches/ubuntu/saucy/python-django/saucy-updates

« back to all changes in this revision

Viewing changes to docs/ref/forms/api.txt

  • Committer: Package Import Robot
  • Author(s): Luke Faraone
  • Date: 2013-08-13 16:49:39 UTC
  • mfrom: (1.3.9)
  • mto: This revision was merged to the branch mainline in revision 47.
  • Revision ID: package-import@ubuntu.com-20130813164939-irlkd7hokvcgocfl
Tags: upstream-1.5.2
ImportĀ upstreamĀ versionĀ 1.5.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
638
638
        >>> str(f['subject'].errors)
639
639
        ''
640
640
 
 
641
.. method:: BoundField.label_tag(contents=None, attrs=None)
 
642
 
 
643
To separately render the label tag of a form field, you can call its
 
644
``label_tag`` method::
 
645
 
 
646
    >>> f = ContactForm(data)
 
647
    >>> print(f['message'].label_tag())
 
648
    <label for="id_message">Message</label>
 
649
 
 
650
Optionally, you can provide the ``contents`` parameter which will replace the
 
651
auto-generated label tag. An optional ``attrs`` dictionary may contain
 
652
additional attributes for the ``<label>`` tag.
 
653
 
641
654
.. method:: BoundField.css_classes()
642
655
 
643
656
When you use Django's rendering shortcuts, CSS classes are used to
670
683
    >>> print(bound_form['subject'].value())
671
684
    hi
672
685
 
 
686
.. attribute:: BoundField.id_for_label
 
687
 
 
688
Use this property to render the ID of this field. For example, if you are
 
689
manually constructing a ``<label>`` in your template (despite the fact that
 
690
:meth:`~BoundField.label_tag` will do this for you):
 
691
 
 
692
.. code-block:: html+django
 
693
 
 
694
    <label for="{{ form.my_field.id_for_label }}">...</label>{{ my_field }}
 
695
 
 
696
By default, this will be the field's name prefixed by ``id_``
 
697
("``id_my_field``" for the example above). You may modify the ID by setting
 
698
:attr:`~django.forms.Widget.attrs` on the field's widget. For example,
 
699
declaring a field like this::
 
700
 
 
701
    my_field = forms.CharField(widget=forms.TextInput(attrs={'id': 'myFIELD'}))
 
702
 
 
703
and using the template above, would render something like:
 
704
 
 
705
.. code-block:: html
 
706
 
 
707
    <label for="myFIELD">...</label><input id="myFIELD" type="text" name="my_field" />
 
708
 
673
709
.. _binding-uploaded-files:
674
710
 
675
711
Binding uploaded files to a form