summaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authorGabe Jackson <gabejackson@cxg.ch>2012-06-08 15:32:35 +0200
committerTim Graham <timograham@gmail.com>2013-06-10 14:23:15 -0400
commit584bd14dcfdee9585fec7794d53ce120ea73d0bc (patch)
tree7303b054d610767073934793ae1223404444c9de /docs
parenta643e4d200e12d1570174fec343a27d6bc47f735 (diff)
Fixed #18134 -- BoundField.label_tag now includes the form's label_suffix
There was an inconsistency between how the label_tag for forms were generated depending on which method was used: as_p, as_ul and as_table contained code to append the label_suffix where as label_tag called on a form field directly did NOT append the label_suffix. The code for appending the label_suffix has been moved in to the label_tag code of the field and the HTML generation code for as_p, as_ul and as_table now calls this code as well. This is a backwards incompatible change because users who have added the label_suffix manually in their templates may now get double label_suffix characters in their forms.
Diffstat (limited to 'docs')
-rw-r--r--docs/ref/forms/api.txt9
-rw-r--r--docs/releases/1.6.txt31
-rw-r--r--docs/topics/forms/index.txt16
-rw-r--r--docs/topics/forms/modelforms.txt2
4 files changed, 51 insertions, 7 deletions
diff --git a/docs/ref/forms/api.txt b/docs/ref/forms/api.txt
index c05430c64e..3c17827800 100644
--- a/docs/ref/forms/api.txt
+++ b/docs/ref/forms/api.txt
@@ -498,6 +498,8 @@ include ``%s`` -- then the library will act as if ``auto_id`` is ``True``.
By default, ``auto_id`` is set to the string ``'id_%s'``.
+.. attribute:: Form.label_suffix
+
Normally, a colon (``:``) will be appended after any label name when a form is
rendered. It's possible to change the colon to another character, or omit it
entirely, using the ``label_suffix`` parameter::
@@ -650,12 +652,17 @@ To separately render the label tag of a form field, you can call its
>>> f = ContactForm(data)
>>> print(f['message'].label_tag())
- <label for="id_message">Message</label>
+ <label for="id_message">Message:</label>
Optionally, you can provide the ``contents`` parameter which will replace the
auto-generated label tag. An optional ``attrs`` dictionary may contain
additional attributes for the ``<label>`` tag.
+.. versionchanged:: 1.6
+
+ The label now includes the form's :attr:`~django.forms.Form.label_suffix`
+ (a semicolon, by default).
+
.. method:: BoundField.css_classes()
When you use Django's rendering shortcuts, CSS classes are used to
diff --git a/docs/releases/1.6.txt b/docs/releases/1.6.txt
index 6736af8c2d..e5cd3273dc 100644
--- a/docs/releases/1.6.txt
+++ b/docs/releases/1.6.txt
@@ -581,6 +581,37 @@ It is still possible to convert the fetched rows to ``Model`` objects
lazily by using the :meth:`~django.db.models.query.QuerySet.iterator()`
method.
+:meth:`BoundField.label_tag<django.forms.BoundField.label_tag>` now includes the form's :attr:`~django.forms.Form.label_suffix`
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+This is consistent with how methods like
+:meth:`Form.as_p<django.forms.Form.as_p>` and
+:meth:`Form.as_ul<django.forms.Form.as_ul>` render labels.
+
+If you manually render ``label_tag`` in your templates:
+
+.. code-block:: html+django
+
+ {{ form.my_field.label_tag }}: {{ form.my_field }}
+
+you'll want to remove the semicolon (or whatever other separator you may be
+using) to avoid duplicating it when upgrading to Django 1.6. The following
+template in Django 1.6 will render identically to the above template in Django
+1.5, except that the semicolon will appear inside the ``<label>`` element.
+
+.. code-block:: html+django
+
+ {{ form.my_field.label_tag }} {{ form.my_field }}
+
+will render something like:
+
+.. code-block:: html
+
+ <label for="id_my_field">My Field:</label> <input id="id_my_field" type="text" name="my_field" />
+
+If you want to keep the current behavior of rendering ``label_tag`` without
+the ``label_suffix``, instantiate the form ``label_suffix=''``.
+
Miscellaneous
~~~~~~~~~~~~~
diff --git a/docs/topics/forms/index.txt b/docs/topics/forms/index.txt
index ac58acc9e3..7d5a0ed411 100644
--- a/docs/topics/forms/index.txt
+++ b/docs/topics/forms/index.txt
@@ -302,7 +302,7 @@ loop::
{% for field in form %}
<div class="fieldWrapper">
{{ field.errors }}
- {{ field.label_tag }}: {{ field }}
+ {{ field.label_tag }} {{ field }}
</div>
{% endfor %}
<p><input type="submit" value="Send message" /></p>
@@ -316,8 +316,14 @@ attributes, which can be useful in your templates:
The label of the field, e.g. ``Email address``.
``{{ field.label_tag }}``
- The field's label wrapped in the appropriate HTML ``<label>`` tag,
- e.g. ``<label for="id_email">Email address</label>``
+ The field's label wrapped in the appropriate HTML ``<label>`` tag.
+
+ .. versionchanged:: 1.6
+
+ This includes the form's :attr:`~django.forms.Form.label_suffix`. For
+ example, the default ``label_suffix`` is a semicolon::
+
+ <label for="id_email">Email address:</label>
``{{ field.value }}``
The value of the field. e.g ``someone@example.com``
@@ -375,7 +381,7 @@ these two methods::
{% for field in form.visible_fields %}
<div class="fieldWrapper">
{{ field.errors }}
- {{ field.label_tag }}: {{ field }}
+ {{ field.label_tag }} {{ field }}
</div>
{% endfor %}
<p><input type="submit" value="Send message" /></p>
@@ -403,7 +409,7 @@ using the :ttag:`include` tag to reuse it in other templates::
{% for field in form %}
<div class="fieldWrapper">
{{ field.errors }}
- {{ field.label_tag }}: {{ field }}
+ {{ field.label_tag }} {{ field }}
</div>
{% endfor %}
diff --git a/docs/topics/forms/modelforms.txt b/docs/topics/forms/modelforms.txt
index 4c46c6c0c0..d325a15cca 100644
--- a/docs/topics/forms/modelforms.txt
+++ b/docs/topics/forms/modelforms.txt
@@ -907,7 +907,7 @@ Third, you can manually render each field::
{{ formset.management_form }}
{% for form in formset %}
{% for field in form %}
- {{ field.label_tag }}: {{ field }}
+ {{ field.label_tag }} {{ field }}
{% endfor %}
{% endfor %}
</form>