Commit 053de613 authored by e0ne's avatar e0ne Committed by Tim Graham
Browse files

Fixed #5749 -- Added field_name as a key in the _html_output dict

Thanks SmileyChris for the suggestion.
parent 4840fd9c
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -185,7 +185,8 @@ class BaseForm(object):
                    'label': force_text(label),
                    'field': six.text_type(bf),
                    'help_text': help_text,
                    'html_class_attr': html_class_attr
                    'html_class_attr': html_class_attr,
                    'field_name': bf.html_name,
                })

        if top_errors:
+11 −0
Original line number Diff line number Diff line
@@ -1950,3 +1950,14 @@ class FormsTestCase(TestCase):
        boundfield = SomeForm(label_suffix='!')['field']

        self.assertHTMLEqual(boundfield.label_tag(label_suffix='$'), '<label for="id_field">Field$</label>')

    def test_field_name(self):
        """#5749 - `field_name` may be used as a key in _html_output()."""
        class SomeForm(Form):
            some_field = CharField()

            def as_p(self):
                return self._html_output(u'<p id="p_%(field_name)s"></p>', u'%s', '</p>', u' %s', True)

        form = SomeForm()
        self.assertHTMLEqual(form.as_p(), '<p id="p_some_field"></p>')