From be0bab1bb8da80402248cd1fa22fd4cc09b34fe7 Mon Sep 17 00:00:00 2001 From: Claude Paroz Date: Sat, 25 May 2013 15:18:48 +0200 Subject: 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. --- django/forms/forms.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'django/forms/forms.py') 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('', - widget.id_for_label(id_), attrs, contents - ) + contents = format_html('{1}', attrs, contents) else: contents = conditional_escape(contents) return mark_safe(contents) -- cgit v1.3