From 87dc0844a634360182bcb74d491508111ef8a652 Mon Sep 17 00:00:00 2001 From: Tim Graham Date: Wed, 14 Mar 2018 11:28:18 -0400 Subject: Fixed #29200 -- Fixed label rendering when using RadioSelect and CheckboxSelectMultiple with MultiWidget. --- django/forms/boundfield.py | 2 +- django/forms/jinja2/django/forms/widgets/input_option.html | 2 +- django/forms/templates/django/forms/widgets/input_option.html | 2 +- django/forms/widgets.py | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) (limited to 'django/forms') 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'): -- cgit v1.3