mirror of
https://github.com/django/django.git
synced 2025-07-31 17:14:14 +00:00
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.
This commit is contained in:
parent
ab61dd2829
commit
be0bab1bb8
3 changed files with 32 additions and 15 deletions
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue