From e86d7cc6f67a4eb0f98cf8fef23e1b569162b835 Mon Sep 17 00:00:00 2001 From: Jean-Louis Jouannic Date: Tue, 5 Jul 2022 21:23:49 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=92=84=20renders=20inputs=20as=20Bootstra?= =?UTF-8?q?p=20radio=20buttons?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/templates/core/child_radio.html | 8 ++++++++ core/templates/core/child_radio_option.html | 3 ++- core/widgets.py | 1 + 3 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 core/templates/core/child_radio.html diff --git a/core/templates/core/child_radio.html b/core/templates/core/child_radio.html new file mode 100644 index 00000000..967d6847 --- /dev/null +++ b/core/templates/core/child_radio.html @@ -0,0 +1,8 @@ +{% with id=widget.attrs.id %} + + {% for group, options, index in widget.optgroups %} + {% for option in options %} + {% include option.template_name with widget=option %} + {% endfor %} + {% endfor %} + {% endwith %} diff --git a/core/templates/core/child_radio_option.html b/core/templates/core/child_radio_option.html index 0e6cb443..9c81c404 100644 --- a/core/templates/core/child_radio_option.html +++ b/core/templates/core/child_radio_option.html @@ -2,7 +2,8 @@ {% if widget.wrap_label %} {% endif %}{% include "django/forms/widgets/input.html" %} + for="{{ widget.attrs.id }}"{% endif %} + class="btn btn-outline-light btn-no-hover">{% endif %}{% include "django/forms/widgets/input.html" %} {% if widget.wrap_label %} {% include "core/child_thumbnail.html" with child=widget %} {{ widget.label }}{% endif %} diff --git a/core/widgets.py b/core/widgets.py index 6c39b944..8860a7a1 100644 --- a/core/widgets.py +++ b/core/widgets.py @@ -85,6 +85,7 @@ class TagsEditor(Widget): class ChildRadioSelect(RadioSelect): input_type = "radio" + template_name = "core/child_radio.html" option_template_name = "core/child_radio_option.html" def create_option(self, name, value, label, selected, index, subindex=None, attrs=None):