From 8b32b56dd9f80736ae25a3e2192f52935e3ebfa7 Mon Sep 17 00:00:00 2001 From: reverend Date: Sat, 10 Apr 2021 08:24:08 +0200 Subject: [PATCH] Custom Widget to select content/invisible radio input --- .../templates/partials/form/inputField.html | 4 +--- .../templates/widgets/select_content.html | 23 +++++++++++++++++++ django_lostplaces/lostplaces/widgets.py | 5 ++++ 3 files changed, 29 insertions(+), 3 deletions(-) create mode 100644 django_lostplaces/lostplaces/templates/widgets/select_content.html create mode 100644 django_lostplaces/lostplaces/widgets.py diff --git a/django_lostplaces/lostplaces/templates/partials/form/inputField.html b/django_lostplaces/lostplaces/templates/partials/form/inputField.html index 8447c67..ce2c155 100644 --- a/django_lostplaces/lostplaces/templates/partials/form/inputField.html +++ b/django_lostplaces/lostplaces/templates/partials/form/inputField.html @@ -2,9 +2,7 @@
- {% with class="LP-Input__Field "%} - {% render_field field class=class%} - {% endwith %} + {% render_field field class+='LP-Input__Field' %} {% if field.errors %} diff --git a/django_lostplaces/lostplaces/templates/widgets/select_content.html b/django_lostplaces/lostplaces/templates/widgets/select_content.html new file mode 100644 index 0000000..5be1cab --- /dev/null +++ b/django_lostplaces/lostplaces/templates/widgets/select_content.html @@ -0,0 +1,23 @@ +
    + {% for group_name, group_choices, group_index in widget.optgroups %} + {% for option in group_choices %} + {% if option.value %} +
  • + + +
  • + {% endif %} + {% endfor %} + {% endfor %} +
\ No newline at end of file diff --git a/django_lostplaces/lostplaces/widgets.py b/django_lostplaces/lostplaces/widgets.py new file mode 100644 index 0000000..6cfa1d4 --- /dev/null +++ b/django_lostplaces/lostplaces/widgets.py @@ -0,0 +1,5 @@ +from django import forms + +class SelectContent(forms.Select): + template_name = 'widgets/select_content.html' + \ No newline at end of file