summaryrefslogtreecommitdiff
path: root/django/newforms/forms.py
diff options
context:
space:
mode:
authorAdrian Holovaty <adrian@holovaty.com>2007-01-20 20:34:35 +0000
committerAdrian Holovaty <adrian@holovaty.com>2007-01-20 20:34:35 +0000
commit23b628d731b69b1cbdddc16417e109bdfe9497e1 (patch)
treec5e8597493b711287096ac3d174bb2844f4014d1 /django/newforms/forms.py
parent5b5930f0df72fbb55fc569cb523217a3b6916762 (diff)
newforms-admin: Merged to [4370]
git-svn-id: http://code.djangoproject.com/svn/django/branches/newforms-admin@4371 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/newforms/forms.py')
-rw-r--r--django/newforms/forms.py9
1 files changed, 6 insertions, 3 deletions
diff --git a/django/newforms/forms.py b/django/newforms/forms.py
index 0b4687bcf3..1724a5a69f 100644
--- a/django/newforms/forms.py
+++ b/django/newforms/forms.py
@@ -6,7 +6,7 @@ from django.utils.datastructures import SortedDict, MultiValueDict
from django.utils.html import escape
from fields import Field
from widgets import TextInput, Textarea, HiddenInput, MultipleHiddenInput
-from util import StrAndUnicode, ErrorDict, ErrorList, ValidationError
+from util import flatatt, StrAndUnicode, ErrorDict, ErrorList, ValidationError
__all__ = ('BaseForm', 'Form')
@@ -247,17 +247,20 @@ class BoundField(StrAndUnicode):
return self.field.widget.value_from_datadict(self.form.data, self.html_name)
data = property(_data)
- def label_tag(self, contents=None):
+ def label_tag(self, contents=None, attrs=None):
"""
Wraps the given contents in a <label>, if the field has an ID attribute.
Does not HTML-escape the contents. If contents aren't given, uses the
field's HTML-escaped label.
+
+ If attrs are given, they're used as HTML attributes on the <label> tag.
"""
contents = contents or escape(self.label)
widget = self.field.widget
id_ = widget.attrs.get('id') or self.auto_id
if id_:
- contents = '<label for="%s">%s</label>' % (widget.id_for_label(id_), contents)
+ attrs = attrs and flatatt(attrs) or ''
+ contents = '<label for="%s"%s>%s</label>' % (widget.id_for_label(id_), attrs, contents)
return contents
def _is_hidden(self):