Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed #20618 -- Fixed regression in `BoundField.label_tag`.

  • Loading branch information...
commit 3128f3d38d1db0bc01da9a4bf4be81119079d73a 1 parent ee77d4b
@bmispelon bmispelon authored
Showing with 9 additions and 3 deletions.
  1. +2 −3 django/forms/forms.py
  2. +7 −0 tests/forms_tests/tests/test_forms.py
View
5 django/forms/forms.py
@@ -518,9 +518,8 @@ def label_tag(self, contents=None, attrs=None):
"""
contents = contents or self.label
# Only add the suffix if the label does not end in punctuation.
- if self.form.label_suffix:
- if contents[-1] not in ':?.!':
- contents = format_html('{0}{1}', contents, self.form.label_suffix)
+ if self.form.label_suffix and contents and contents[-1] not in ':?.!':
+ contents = format_html('{0}{1}', contents, self.form.label_suffix)
widget = self.field.widget
id_ = widget.attrs.get('id') or self.auto_id
if id_:
View
7 tests/forms_tests/tests/test_forms.py
@@ -1863,3 +1863,10 @@ class SomeForm(Form):
form = SomeForm()
self.assertHTMLEqual(form['custom'].label_tag(), '<label for="custom_id_custom">Custom:</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>')
Please sign in to comment.
Something went wrong with that request. Please try again.