summaryrefslogtreecommitdiff
path: root/django/forms
diff options
context:
space:
mode:
authorDavid Smith <smithdc@gmail.com>2022-05-05 09:21:47 +0200
committerCarlton Gibson <carlton@noumenal.es>2022-05-05 14:32:43 +0200
commitec5659382a5f5fc2daf0c87ccc89d0fb07534874 (patch)
tree08a5183708f3490b97f61098d26272901d25b822 /django/forms
parent27b07a3246bc033cd9ded01238c6dc64731cce35 (diff)
Fixed #32339 -- Added div.html form template.
Diffstat (limited to 'django/forms')
-rw-r--r--django/forms/forms.py1
-rw-r--r--django/forms/formsets.py1
-rw-r--r--django/forms/jinja2/django/forms/div.html24
-rw-r--r--django/forms/jinja2/django/forms/formsets/div.html1
-rw-r--r--django/forms/templates/django/forms/div.html24
-rw-r--r--django/forms/templates/django/forms/formsets/div.html1
-rw-r--r--django/forms/utils.py4
7 files changed, 56 insertions, 0 deletions
diff --git a/django/forms/forms.py b/django/forms/forms.py
index 2500dccc9b..35471345c9 100644
--- a/django/forms/forms.py
+++ b/django/forms/forms.py
@@ -66,6 +66,7 @@ class BaseForm(RenderableFormMixin):
prefix = None
use_required_attribute = True
+ template_name_div = "django/forms/div.html"
template_name_p = "django/forms/p.html"
template_name_table = "django/forms/table.html"
template_name_ul = "django/forms/ul.html"
diff --git a/django/forms/formsets.py b/django/forms/formsets.py
index d51b13548e..2df80297d3 100644
--- a/django/forms/formsets.py
+++ b/django/forms/formsets.py
@@ -63,6 +63,7 @@ class BaseFormSet(RenderableFormMixin):
),
}
+ template_name_div = "django/forms/formsets/div.html"
template_name_p = "django/forms/formsets/p.html"
template_name_table = "django/forms/formsets/table.html"
template_name_ul = "django/forms/formsets/ul.html"
diff --git a/django/forms/jinja2/django/forms/div.html b/django/forms/jinja2/django/forms/div.html
new file mode 100644
index 0000000000..6de0bb038e
--- /dev/null
+++ b/django/forms/jinja2/django/forms/div.html
@@ -0,0 +1,24 @@
+{{ errors }}
+{% if errors and not fields %}
+ <div>{% for field in hidden_fields %}{{ field }}{% endfor %}</div>
+{% endif %}
+{% for field, errors in fields %}
+ <div{% set classes = field.css_classes() %}{% if classes %} class="{{ classes }}"{% endif %}>
+ {% if field.use_fieldset %}
+ <fieldset>
+ {% if field.label %}{{ field.legend_tag() }}{% endif %}
+ {% else %}
+ {% if field.label %}{{ field.label_tag() }}{% endif %}
+ {% endif %}
+ {% if field.help_text %}<div class="helptext">{{ field.help_text|safe }}</div>{% endif %}
+ {{ errors }}
+ {{ field }}
+ {% if field.use_fieldset %}</fieldset>{% endif %}
+ {% if loop.last %}
+ {% for field in hidden_fields %}{{ field }}{% endfor %}
+ {% endif %}
+</div>
+{% endfor %}
+{% if not fields and not errors %}
+ {% for field in hidden_fields %}{{ field }}{% endfor %}
+{% endif %}
diff --git a/django/forms/jinja2/django/forms/formsets/div.html b/django/forms/jinja2/django/forms/formsets/div.html
new file mode 100644
index 0000000000..0dda779d3f
--- /dev/null
+++ b/django/forms/jinja2/django/forms/formsets/div.html
@@ -0,0 +1 @@
+{{ formset.management_form }}{% for form in formset %}{{ form.as_div() }}{% endfor %}
diff --git a/django/forms/templates/django/forms/div.html b/django/forms/templates/django/forms/div.html
new file mode 100644
index 0000000000..0328fdf8d3
--- /dev/null
+++ b/django/forms/templates/django/forms/div.html
@@ -0,0 +1,24 @@
+{{ errors }}
+{% if errors and not fields %}
+ <div>{% for field in hidden_fields %}{{ field }}{% endfor %}</div>
+{% endif %}
+{% for field, errors in fields %}
+ <div{% with classes=field.css_classes %}{% if classes %} class="{{ classes }}"{% endif %}{% endwith %}>
+ {% if field.use_fieldset %}
+ <fieldset>
+ {% if field.label %}{{ field.legend_tag }}{% endif %}
+ {% else %}
+ {% if field.label %}{{ field.label_tag }}{% endif %}
+ {% endif %}
+ {% if field.help_text %}<div class="helptext">{{ field.help_text|safe }}</div>{% endif %}
+ {{ errors }}
+ {{ field }}
+ {% if field.use_fieldset %}</fieldset>{% endif %}
+ {% if forloop.last %}
+ {% for field in hidden_fields %}{{ field }}{% endfor %}
+ {% endif %}
+</div>
+{% endfor %}
+{% if not fields and not errors %}
+ {% for field in hidden_fields %}{{ field }}{% endfor %}
+{% endif %}
diff --git a/django/forms/templates/django/forms/formsets/div.html b/django/forms/templates/django/forms/formsets/div.html
new file mode 100644
index 0000000000..93499897d4
--- /dev/null
+++ b/django/forms/templates/django/forms/formsets/div.html
@@ -0,0 +1 @@
+{{ formset.management_form }}{% for form in formset %}{{ form.as_div }}{% endfor %}
diff --git a/django/forms/utils.py b/django/forms/utils.py
index 7d3bb5ad48..77678054db 100644
--- a/django/forms/utils.py
+++ b/django/forms/utils.py
@@ -73,6 +73,10 @@ class RenderableFormMixin(RenderableMixin):
"""Render as <li> elements excluding the surrounding <ul> tag."""
return self.render(self.template_name_ul)
+ def as_div(self):
+ """Render as <div> elements."""
+ return self.render(self.template_name_div)
+
class RenderableErrorMixin(RenderableMixin):
def as_json(self, escape_html=False):