Fixed #20618 -- Fixed regression in `BoundField.label_tag`.
This commit is contained in:
parent
ee77d4b253
commit
3128f3d38d
|
@ -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_:
|
||||
|
|
|
@ -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>')
|
||||
|
|
Loading…
Reference in New Issue