diff options
| author | Maxime Lorant <maxime.lorant@gmail.com> | 2015-08-21 18:49:14 +0200 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2015-08-22 10:08:59 -0400 |
| commit | 7d60659e22c869149cc17f2568a8e073412ea219 (patch) | |
| tree | 5a30a35f7bda1f65b6d0945c47915f61dd5896f6 | |
| parent | 26dcf739eaf5577c5072eb8c9ba1c5ac5605683f (diff) | |
Fixed #25300 -- Added unit tests for BoundField.id_for_label
| -rw-r--r-- | tests/forms_tests/tests/test_forms.py | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/tests/forms_tests/tests/test_forms.py b/tests/forms_tests/tests/test_forms.py index acd1b6840a..8aece32c90 100644 --- a/tests/forms_tests/tests/test_forms.py +++ b/tests/forms_tests/tests/test_forms.py @@ -2289,6 +2289,25 @@ class FormsTestCase(SimpleTestCase): 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): """ BoundField label_suffix (if provided) overrides Form label_suffix |
