Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fixed #5749 -- Added field_name as a key in the _html_output dict
Thanks SmileyChris for the suggestion.
  • Loading branch information
e0ne authored and timgraham committed Sep 10, 2013
1 parent 4840fd9 commit 053de61
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
3 changes: 2 additions & 1 deletion django/forms/forms.py
Expand Up @@ -185,7 +185,8 @@ def _html_output(self, normal_row, error_row, row_ender, help_text_html, errors_
'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:
Expand Down
11 changes: 11 additions & 0 deletions tests/forms_tests/tests/test_forms.py
Expand Up @@ -1950,3 +1950,14 @@ class SomeForm(Form):
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>')

0 comments on commit 053de61

Please sign in to comment.