Kaydet (Commit) 7d60659e authored tarafından Maxime Lorant's avatar Maxime Lorant Kaydeden (comit) Tim Graham

Fixed #25300 -- Added unit tests for BoundField.id_for_label

üst 26dcf739
...@@ -2289,6 +2289,25 @@ class FormsTestCase(SimpleTestCase): ...@@ -2289,6 +2289,25 @@ class FormsTestCase(SimpleTestCase):
self.assertHTMLEqual(boundfield.label_tag(), '<label for="id_field"></label>') self.assertHTMLEqual(boundfield.label_tag(), '<label for="id_field"></label>')
def test_boundfield_id_for_label(self):
class SomeForm(Form):
field = CharField(label='')
self.assertEqual(SomeForm()['field'].id_for_label, 'id_field')
def test_boundfield_id_for_label_override_by_attrs(self):
"""
If an id is provided in `Widget.attrs`, it overrides the generated ID,
unless it is `None`.
"""
class SomeForm(Form):
field = CharField(widget=forms.TextInput(attrs={'id': 'myCustomID'}))
field_none = CharField(widget=forms.TextInput(attrs={'id': None}))
form = SomeForm()
self.assertEqual(form['field'].id_for_label, 'myCustomID')
self.assertEqual(form['field_none'].id_for_label, 'id_field_none')
def test_label_tag_override(self): def test_label_tag_override(self):
""" """
BoundField label_suffix (if provided) overrides Form label_suffix BoundField label_suffix (if provided) overrides Form label_suffix
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment