diff options
| author | Baptiste Mispelon <bmispelon@gmail.com> | 2013-06-18 17:49:45 +0200 |
|---|---|---|
| committer | Baptiste Mispelon <bmispelon@gmail.com> | 2013-06-18 17:49:53 +0200 |
| commit | 3128f3d38d1db0bc01da9a4bf4be81119079d73a (patch) | |
| tree | 57e5f7056a17a807f25a5f7872bfdc72d3067533 | |
| parent | ee77d4b25360a9fc050c32769a334fd69a011a63 (diff) | |
Fixed #20618 -- Fixed regression in `BoundField.label_tag`.
| -rw-r--r-- | django/forms/forms.py | 5 | ||||
| -rw-r--r-- | tests/forms_tests/tests/test_forms.py | 7 |
2 files changed, 9 insertions, 3 deletions
diff --git a/django/forms/forms.py b/django/forms/forms.py index e6a11f28fb..b25eeb30a4 100644 --- a/django/forms/forms.py +++ b/django/forms/forms.py @@ -518,9 +518,8 @@ class BoundField(object): """ 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_: diff --git a/tests/forms_tests/tests/test_forms.py b/tests/forms_tests/tests/test_forms.py index 3b722e5ac1..633fde5026 100644 --- a/tests/forms_tests/tests/test_forms.py +++ b/tests/forms_tests/tests/test_forms.py @@ -1863,3 +1863,10 @@ class FormsTestCase(TestCase): 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>') |
