Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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

Thanks SmileyChris for the suggestion.
  • Loading branch information...
commit 053de6131af83c63ec17d38578889c71de913d24 1 parent 4840fd9
Ivan Kolodyazhny authored September 10, 2013 timgraham committed September 10, 2013
3  django/forms/forms.py
@@ -185,7 +185,8 @@ def _html_output(self, normal_row, error_row, row_ender, help_text_html, errors_
185 185
                     'label': force_text(label),
186 186
                     'field': six.text_type(bf),
187 187
                     'help_text': help_text,
188  
-                    'html_class_attr': html_class_attr
  188
+                    'html_class_attr': html_class_attr,
  189
+                    'field_name': bf.html_name,
189 190
                 })
190 191
 
191 192
         if top_errors:
11  tests/forms_tests/tests/test_forms.py
@@ -1950,3 +1950,14 @@ class SomeForm(Form):
1950 1950
         boundfield = SomeForm(label_suffix='!')['field']
1951 1951
 
1952 1952
         self.assertHTMLEqual(boundfield.label_tag(label_suffix='$'), '<label for="id_field">Field$</label>')
  1953
+
  1954
+    def test_field_name(self):
  1955
+        """#5749 - `field_name` may be used as a key in _html_output()."""
  1956
+        class SomeForm(Form):
  1957
+            some_field = CharField()
  1958
+
  1959
+            def as_p(self):
  1960
+                return self._html_output(u'<p id="p_%(field_name)s"></p>', u'%s', '</p>', u' %s', True)
  1961
+
  1962
+        form = SomeForm()
  1963
+        self.assertHTMLEqual(form.as_p(), '<p id="p_some_field"></p>')

0 notes on commit 053de61

Please sign in to comment.
Something went wrong with that request. Please try again.