{# comment : Allows to display the fields with DSFR layout #} {% load static dsfr_tags %} {# comment : Widget tweaks allows to add classes to the html elements with add_class #} {% load widget_tweaks %} {# comment : if formset #} {% block form-set %} {% if formset %}
{{ formset.management_form }} {% block formset-title %} {% endblock formset-title %} {% for form in formset %}
{% for hidden in form.hidden_fields %} {{ hidden }} {% endfor %} {% for field in form.visible_fields %} {# comment : everything that needs to be in the loop for each field for each form in formset #} {% block inside-formset-field %} {% endblock inside-formset-field %} {# comment : Check the widget class and adds the DSFR class corresponding #} {# comment : Select lists #} {% if field|widget_type == 'select' or field|widget_type == 'selectmultiple' or field|widget_type == 'selectdate' %}
{{ field|add_class:'fr-select'|add_error_class:'fr-select--error'|add_error_attr:"aria-describedby:select-error-desc-error"|add_error_attr:"id:select-error"|add_error_attr:"name:select-error" }} {% if form.errors %} {% for error in field.errors %}

{{ error }}

{% endfor %} {% endif %}
{# comment : SplitDateTimeWidget : currently doesn't work #} {% elif field|widget_type == 'splitdatetimewidget' or field|widget_type == 'splithiddendatetimewidget' %}

Attention : pas encore fonctionnel

{{ field|add_class:'fr-select'|add_error_class:'fr-select--error'|add_error_attr:"aria-describedby:select-error-desc-error"|add_error_attr:"id:select-error"|add_error_attr:"name:select-error" }} {% if form.errors %} {% for error in field.errors %}

{{ error }}

{% endfor %} {% endif %}
{# comment : Single checkbox #} {% elif field|widget_type == 'checkboxinput' %}
{{ field|attr:"type:checkbox"|add_error_attr:"aria-describedby:checkboxes-error-desc-error"|add_error_attr:"id:checkbox-error"|add_error_attr:"name:checkbox-error" }} {% if form.errors %} {% for error in field.errors %}

{{ error }}

{% endfor %} {% endif %}
{# comment : Multiple checkboxes. For some reason, the checkboxes are displayed small #} {% elif field|widget_type == 'checkboxselectmultiple' %}
{{ field.label }} {% if field.field.required %}*{% endif %} {% if field.help_text %} {{ field.help_text }} {% endif %}
{{ field|attr:"type:checkbox"|add_error_attr:"id:checkboxes-error"|add_error_attr:"name:checkboxes-error"|remove_attr:"class" }}
{% if form.errors %} {% for error in field.errors %}

{{ error }}

{% endfor %} {% endif %}
{# comment : Radio buttons. For some reason, the radio buttons are displayed small #} {% elif field|widget_type == 'radioselect' %}
{{ field.label }} {% if field.field.required %}*{% endif %} {% if field.help_text %} {{ field.help_text }} {% endif %}
{{ field|attr:"type:radio"|add_error_attr:"aria-describedby:radio-error-desc-error"|add_error_attr:"id:radio-error"|add_error_attr:"name:radio-error"|remove_attr:"class" }}
{% if form.errors %} {% for error in field.errors %}

{{ error }}

{% endfor %} {% endif %}
{# comment : Date input #} {% elif field|widget_type == 'dateinput' %}
{{ field|add_class:'fr-input'|attr:"type:date" }} {% if form.errors %} {% for error in field.errors %}

{{ error }}

{% endfor %} {% endif %}
{# comment : Datetime input. Currently doesn't work on FireFox #} {% elif field|widget_type == 'datetimeinput' %}
{{ field|add_class:'fr-input'|attr:"type:datetime-local" }} {% if form.errors %} {% for error in field.errors %}

{{ error }}

{% endfor %} {% endif %}
{# comment : Time input #} {% elif field|widget_type == 'timeinput' %}
{{ field|add_class:'fr-input'|attr:"type:time" }} {% if form.errors %} {% for error in field.errors %}

{{ error }}

{% endfor %} {% endif %}
{# comment : Textarea #} {% elif field|widget_type == 'textarea' %}
{% if field.field.required %}
{{ field|add_class:"fr-input"|add_error_class:"fr-input--error" }}
{% else %} {{ field|add_class:"fr-input"|add_error_class:"fr-input--error" }} {% endif %} {% if form.errors %} {% for error in field.errors %}

{{ error }}

{% endfor %} {% endif %}
{# comment : File input #} {# comment : ClearableFileInput can't be cleared #} {% elif 'file' in field|widget_type %}
{% if field|widget_type == 'clearablefileinput' %}

Attention : ne peux pas être vidé

{% endif %} {{ field|add_class:'fr-upload' }} {% if form.errors %} {% for error in field.errors %}

{{ error }}

{% endfor %} {% endif %}
{# comment : Number input #} {% elif field|widget_type == 'numberinput' %}
{{ field|add_class:'fr-input'|attr:"pattern:[0-9]*"|attr:"inputmode:numeric"|attr:"type:number"|add_error_class:"fr-input--error" }} {% if form.errors %} {% for error in field.errors %}

{{ error }}

{% endfor %} {% endif %}
{# comment : URL input #} {% elif field|widget_type == 'urlinput' %}
{% if field.field.required %}
{{ field|add_class:'fr-input'|add_error_class:"fr-input--error"|attr:"placeholder:https://"|add_error_class:"fr-input--error" }}
{% else %} {{ field|add_class:'fr-input'|add_error_class:"fr-input--error"|attr:"placeholder:https://" }} {% endif %} {% if form.errors %} {% for error in field.errors %}

{{ error }}

{% endfor %} {% endif %}
{# comment : Text input or other cases #} {% else %}
{% if field.field.required %}
{{ field|add_class:'fr-input'|add_error_class:"fr-input--error" }}
{% else %} {{ field|add_class:'fr-input'|add_error_class:"fr-input--error" }} {% endif %} {% if form.errors %} {% for error in field.errors %}

{{ error }}

{% endfor %} {% endif %}
{% endif %} {% endfor %}
{% endfor %}

{% endif %} {% endblock form-set %} {% block extra_js %} {% endblock %}