From eba9a9b7f72995206af867600d6685b5405f172a Mon Sep 17 00:00:00 2001 From: David Smith Date: Sat, 6 Nov 2021 06:50:29 +0000 Subject: [PATCH] Refs #32338 -- Added Boundfield.legend_tag(). --- django/forms/boundfield.py | 15 ++- django/forms/jinja2/django/forms/label.html | 2 +- .../forms/templates/django/forms/label.html | 2 +- docs/ref/forms/api.txt | 36 ++++-- docs/releases/4.1.txt | 4 +- .../templates/forms_tests/legend_test.html | 7 ++ tests/forms_tests/tests/test_forms.py | 117 ++++++++++++++++-- tests/forms_tests/tests/test_i18n.py | 8 ++ .../test_checkboxselectmultiple.py | 1 + tests/model_forms/tests.py | 12 ++ tests/model_formsets/tests.py | 8 ++ 11 files changed, 188 insertions(+), 24 deletions(-) create mode 100644 tests/forms_tests/templates/forms_tests/legend_test.html diff --git a/django/forms/boundfield.py b/django/forms/boundfield.py index 5bbfcbe41c..62d1823d57 100644 --- a/django/forms/boundfield.py +++ b/django/forms/boundfield.py @@ -145,7 +145,7 @@ class BoundField: initial_value = self.initial return field.has_changed(initial_value, self.data) - def label_tag(self, contents=None, attrs=None, label_suffix=None): + def label_tag(self, contents=None, attrs=None, label_suffix=None, tag=None): """ Wrap the given contents in a {% else %}{{ label }}{% endif %} +{% if use_tag %}<{{ tag }}{% if attrs %}{% include 'django/forms/attrs.html' %}{% endif %}>{{ label }}{% else %}{{ label }}{% endif %} diff --git a/django/forms/templates/django/forms/label.html b/django/forms/templates/django/forms/label.html index eb2a9f7973..0eba630e82 100644 --- a/django/forms/templates/django/forms/label.html +++ b/django/forms/templates/django/forms/label.html @@ -1 +1 @@ -{% if use_tag %}{{ label }}{% else %}{{ label }}{% endif %} +{% if use_tag %}<{{ tag }}{% include 'django/forms/attrs.html' %}>{{ label }}{% else %}{{ label }}{% endif %} diff --git a/docs/ref/forms/api.txt b/docs/ref/forms/api.txt index d80d9ea224..e092a2f59e 100644 --- a/docs/ref/forms/api.txt +++ b/docs/ref/forms/api.txt @@ -542,9 +542,9 @@ default template, see also :ref:`overriding-built-in-form-templates`. .. attribute:: Form.template_name_label The template used to render a field's ``