Skip to content

Commit

Permalink
Fixed #20618 -- Fixed regression in BoundField.label_tag.
Browse files Browse the repository at this point in the history
  • Loading branch information
bmispelon committed Jun 18, 2013
1 parent ee77d4b commit 3128f3d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
5 changes: 2 additions & 3 deletions django/forms/forms.py
Expand Up @@ -518,9 +518,8 @@ def label_tag(self, contents=None, attrs=None):
""" """
contents = contents or self.label contents = contents or self.label
# Only add the suffix if the label does not end in punctuation. # Only add the suffix if the label does not end in punctuation.
if self.form.label_suffix: if self.form.label_suffix and contents and contents[-1] not in ':?.!':
if contents[-1] not in ':?.!': contents = format_html('{0}{1}', contents, self.form.label_suffix)
contents = format_html('{0}{1}', contents, self.form.label_suffix)
widget = self.field.widget widget = self.field.widget
id_ = widget.attrs.get('id') or self.auto_id id_ = widget.attrs.get('id') or self.auto_id
if id_: if id_:
Expand Down
7 changes: 7 additions & 0 deletions tests/forms_tests/tests/test_forms.py
Expand Up @@ -1863,3 +1863,10 @@ class SomeForm(Form):
form = SomeForm() form = SomeForm()
self.assertHTMLEqual(form['custom'].label_tag(), '<label for="custom_id_custom">Custom:</label>') self.assertHTMLEqual(form['custom'].label_tag(), '<label for="custom_id_custom">Custom:</label>')
self.assertHTMLEqual(form['empty'].label_tag(), '<label>Empty:</label>') self.assertHTMLEqual(form['empty'].label_tag(), '<label>Empty:</label>')

def test_boundfield_empty_label(self):
class SomeForm(Form):
field = CharField(label='')
boundfield = SomeForm()['field']

self.assertHTMLEqual(boundfield.label_tag(), '<label for="id_field"></label>')

0 comments on commit 3128f3d

Please sign in to comment.