Commit 3128f3d3 authored by Baptiste Mispelon's avatar Baptiste Mispelon
Browse files

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

parent ee77d4b2
Loading
Loading
Loading
Loading
+2 −3
Original line number Diff line number Diff line
@@ -518,8 +518,7 @@ 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 ':?.!':
        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
+7 −0
Original line number Diff line number Diff line
@@ -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>')