Skip to content

Commit

Permalink
Fix the radio select widgets (#40)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ash-Crow authored Feb 9, 2023
1 parent f469aef commit c341a05
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 2 deletions.
1 change: 1 addition & 0 deletions dsfr/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
13 changes: 13 additions & 0 deletions dsfr/templates/django/forms/widgets/radio_option.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{% if widget.attrs.dsfr == "dsfr" %}<div class="fr-radio-group">{% endif %}
{% include "django/forms/widgets/input.html" %}
{% if widget.wrap_label %}
<label class="fr-label"{% if widget.attrs.id %} for="{{ widget.attrs.id }}"{% endif %}>
{% if widget.label.label %}
{{ widget.label.label }}
<span class="fr-hint-text">{{ widget.label.help_text }}</span>
{% else %}
{{ widget.label }}
{% endif %}
</label>
{% endif %}
{% if widget.attrs.dsfr == "dsfr" %}</div>{% endif %}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{% load widget_tweaks %}
<div class="fr-form-group{% if field.errors %} fr-form-group--error{% endif %}{% if field.field.disabled %} fr-form-group--disabled{% endif %}">
<fieldset class="fr-fieldset">
<legend class="fr-fieldset__legend fr-text--regular" id='checkboxes-legend'>
<legend class="fr-fieldset__legend fr-text--regular" id="checkboxes-legend-{{ field.auto_id }}">
{{ field.label_tag }}{% if field.field.required %} *{% endif %}
{% if field.help_text %}<span class="fr-hint-text">{{ field.help_text }}</span>{% endif %}
</legend>
Expand Down
2 changes: 2 additions & 0 deletions dsfr/templates/dsfr/form_field_snippets/field_snippet.html
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}
19 changes: 19 additions & 0 deletions dsfr/templates/dsfr/form_field_snippets/radioselect_snippet.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{% load widget_tweaks %}
<div class="fr-form-group{% if field.errors %} fr-form-group--error{% endif %}{% if field.field.disabled %} fr-form-group--disabled{% endif %}">
<fieldset class="fr-fieldset">
<legend class="fr-fieldset__legend fr-text--regular" id="radio-legend-{{ field.auto_id }}">
{{ field.label_tag }}{% if field.field.required %} *{% endif %}
{% if field.help_text %}<span class="fr-hint-text">{{ field.help_text }}</span>{% endif %}
</legend>

<div class="fr-fieldset__content">
{{ field|add_class:"fr-radio-group" }}
</div>

{% if field.errors %}
<div id="{{ field.auto_id }}-desc-error" class="fr-error-text">
{{ field.errors }}
</div>
{% endif %}
</fieldset>
</div>
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ authors = ["Sylvain Boissel <[email protected]>"]
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",
Expand Down

0 comments on commit c341a05

Please sign in to comment.