From c341a05f02b39c803c8737b8162e1ba249c1b1a3 Mon Sep 17 00:00:00 2001 From: Sylvain Boissel Date: Thu, 9 Feb 2023 15:41:12 +0100 Subject: [PATCH] Fix the radio select widgets (#40) --- dsfr/forms.py | 1 + .../django/forms/widgets/radio_option.html | 13 +++++++++++++ .../checkboxselectmultiple_snippet.html | 2 +- .../form_field_snippets/field_snippet.html | 2 ++ .../radioselect_snippet.html | 19 +++++++++++++++++++ pyproject.toml | 2 +- 6 files changed, 37 insertions(+), 2 deletions(-) create mode 100644 dsfr/templates/django/forms/widgets/radio_option.html create mode 100644 dsfr/templates/dsfr/form_field_snippets/radioselect_snippet.html diff --git a/dsfr/forms.py b/dsfr/forms.py index eb4f7ebcc..2d6bd08e8 100644 --- a/dsfr/forms.py +++ b/dsfr/forms.py @@ -31,6 +31,7 @@ def __init__(self, *args, **kwargs): visible.field.widget.attrs["class"] = "fr-select" visible.field.widget.group_class = "fr-select-group" elif type(visible.field.widget) == forms.widgets.RadioSelect: + visible.field.widget.attrs["dsfr"] = "dsfr" visible.field.widget.group_class = "fr-radio-group" elif type(visible.field.widget) == forms.widgets.CheckboxSelectMultiple: visible.field.widget.attrs["dsfr"] = "dsfr" diff --git a/dsfr/templates/django/forms/widgets/radio_option.html b/dsfr/templates/django/forms/widgets/radio_option.html new file mode 100644 index 000000000..d880ef52b --- /dev/null +++ b/dsfr/templates/django/forms/widgets/radio_option.html @@ -0,0 +1,13 @@ +{% if widget.attrs.dsfr == "dsfr" %}
{% endif %} +{% include "django/forms/widgets/input.html" %} +{% if widget.wrap_label %} + +{% endif %} +{% if widget.attrs.dsfr == "dsfr" %}
{% endif %} \ No newline at end of file diff --git a/dsfr/templates/dsfr/form_field_snippets/checkboxselectmultiple_snippet.html b/dsfr/templates/dsfr/form_field_snippets/checkboxselectmultiple_snippet.html index ca37c7cba..53df1c358 100644 --- a/dsfr/templates/dsfr/form_field_snippets/checkboxselectmultiple_snippet.html +++ b/dsfr/templates/dsfr/form_field_snippets/checkboxselectmultiple_snippet.html @@ -1,7 +1,7 @@ {% load widget_tweaks %}
- + {{ field.label_tag }}{% if field.field.required %} *{% endif %} {% if field.help_text %}{{ field.help_text }}{% endif %} diff --git a/dsfr/templates/dsfr/form_field_snippets/field_snippet.html b/dsfr/templates/dsfr/form_field_snippets/field_snippet.html index 057f6af64..e5f514435 100644 --- a/dsfr/templates/dsfr/form_field_snippets/field_snippet.html +++ b/dsfr/templates/dsfr/form_field_snippets/field_snippet.html @@ -4,6 +4,8 @@ {% include "dsfr/form_field_snippets/checkbox_snippet.html" %} {% elif field|widget_type == "checkboxselectmultiple" %} {% include "dsfr/form_field_snippets/checkboxselectmultiple_snippet.html" %} +{% elif field|widget_type == "radioselect" %} + {% include "dsfr/form_field_snippets/radioselect_snippet.html" %} {% else %} {% include "dsfr/form_field_snippets/input_snippet.html" %} {% endif %} \ No newline at end of file diff --git a/dsfr/templates/dsfr/form_field_snippets/radioselect_snippet.html b/dsfr/templates/dsfr/form_field_snippets/radioselect_snippet.html new file mode 100644 index 000000000..2d8719efe --- /dev/null +++ b/dsfr/templates/dsfr/form_field_snippets/radioselect_snippet.html @@ -0,0 +1,19 @@ +{% load widget_tweaks %} +
+
+ + {{ field.label_tag }}{% if field.field.required %} *{% endif %} + {% if field.help_text %}{{ field.help_text }}{% endif %} + + +
+ {{ field|add_class:"fr-radio-group" }} +
+ + {% if field.errors %} +
+ {{ field.errors }} +
+ {% endif %} +
+
diff --git a/pyproject.toml b/pyproject.toml index 6157e4f28..c79ef885f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -3,7 +3,7 @@ authors = ["Sylvain Boissel "] description = "Integrate the French government Design System into a Django app" license = "MIT" name = "django-dsfr" -version = "0.13.0" +version = "0.13.1" classifiers = [ "Development Status :: 3 - Alpha", "Environment :: Web Environment",