diff options
| author | Claude Paroz <claude@2xlibre.net> | 2013-05-25 15:18:48 +0200 |
|---|---|---|
| committer | Claude Paroz <claude@2xlibre.net> | 2013-05-25 15:31:07 +0200 |
| commit | be0bab1bb8da80402248cd1fa22fd4cc09b34fe7 (patch) | |
| tree | 27e30e05e95c0a9577bc6fbad7796576b10fbe18 /django | |
| parent | ab61dd28293746e26f2aa8728be5f04d6e7e536c (diff) | |
Fixed #11725 -- Made possible to create widget label tag without "for"
Thanks Denis Martinez for the report and initial patch, and
Sergey Kolosov for bringing the patch up to date.
Diffstat (limited to 'django')
| -rw-r--r-- | django/forms/forms.py | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/django/forms/forms.py b/django/forms/forms.py index fece2158ac..2c173a45dc 100644 --- a/django/forms/forms.py +++ b/django/forms/forms.py @@ -525,10 +525,11 @@ class BoundField(object): widget = self.field.widget id_ = widget.attrs.get('id') or self.auto_id if id_: + id_for_label = widget.id_for_label(id_) + if id_for_label: + attrs = dict(attrs or {}, **{'for': id_for_label}) attrs = flatatt(attrs) if attrs else '' - contents = format_html('<label for="{0}"{1}>{2}</label>', - widget.id_for_label(id_), attrs, contents - ) + contents = format_html('<label{0}>{1}</label>', attrs, contents) else: contents = conditional_escape(contents) return mark_safe(contents) |
