diff --git a/django/forms/boundfield.py b/django/forms/boundfield.py index d0ddd9715b..7f40fbbbb4 100644 --- a/django/forms/boundfield.py +++ b/django/forms/boundfield.py @@ -248,7 +248,7 @@ class BoundWidget: return self.tag(wrap_label=True) def tag(self, wrap_label=False): - context = {'widget': self.data, 'wrap_label': wrap_label} + context = {'widget': {**self.data, 'wrap_label': wrap_label}} return self.parent_widget._render(self.template_name, context, self.renderer) @property diff --git a/django/forms/jinja2/django/forms/widgets/input_option.html b/django/forms/jinja2/django/forms/widgets/input_option.html index 3f7085a4f0..48cd65b93a 100644 --- a/django/forms/jinja2/django/forms/widgets/input_option.html +++ b/django/forms/jinja2/django/forms/widgets/input_option.html @@ -1 +1 @@ -{% if wrap_label %}{% endif %}{% include "django/forms/widgets/input.html" %}{% if wrap_label %} {{ widget.label }}{% endif %} +{% if widget.wrap_label %}{% endif %}{% include "django/forms/widgets/input.html" %}{% if widget.wrap_label %} {{ widget.label }}{% endif %} diff --git a/django/forms/templates/django/forms/widgets/input_option.html b/django/forms/templates/django/forms/widgets/input_option.html index 3f7085a4f0..48cd65b93a 100644 --- a/django/forms/templates/django/forms/widgets/input_option.html +++ b/django/forms/templates/django/forms/widgets/input_option.html @@ -1 +1 @@ -{% if wrap_label %}{% endif %}{% include "django/forms/widgets/input.html" %}{% if wrap_label %} {{ widget.label }}{% endif %} +{% if widget.wrap_label %}{% endif %}{% include "django/forms/widgets/input.html" %}{% if widget.wrap_label %} {{ widget.label }}{% endif %} diff --git a/django/forms/widgets.py b/django/forms/widgets.py index 50e41b59ec..566bdf25d6 100644 --- a/django/forms/widgets.py +++ b/django/forms/widgets.py @@ -621,12 +621,12 @@ class ChoiceWidget(Widget): 'attrs': option_attrs, 'type': self.input_type, 'template_name': self.option_template_name, + 'wrap_label': True, } def get_context(self, name, value, attrs): context = super().get_context(name, value, attrs) context['widget']['optgroups'] = self.optgroups(name, context['widget']['value'], attrs) - context['wrap_label'] = True return context def id_for_label(self, id_, index='0'): diff --git a/docs/releases/2.1.txt b/docs/releases/2.1.txt index b22f27dcd7..aa4c6b14a4 100644 --- a/docs/releases/2.1.txt +++ b/docs/releases/2.1.txt @@ -310,6 +310,15 @@ If you want to continue to allow those passwords to be used, you'll have to define the :setting:`PASSWORD_HASHERS` setting (if you don't already) and include ``'django.contrib.auth.hashers.BCryptPasswordHasher'``. +Moved ``wrap_label`` widget template context variable +----------------------------------------------------- + +To fix the lack of ``