- commit
- 9a4b1022ad3795d3332c762f35f4b63dabd2fede
- parent
- b14679af7af0163338183979ec3da9cd4a3143cf
- Author
- Tobias Bengfort <tobias.bengfort@posteo.de>
- Date
- 2021-06-08 07:52
use fieldsets where appropriate see https://code.djangoproject.com/ticket/32338
Diffstat
| M | django_bs4/templates/bs4/field.html | 10 | +++++++--- |
| M | django_bs4/templates/django/forms/widgets/multiwidget.html | 4 | ++-- |
| M | django_bs4/templatetags/bootstrap4.py | 8 | ++++---- |
3 files changed, 13 insertions, 9 deletions
diff --git a/django_bs4/templates/bs4/field.html b/django_bs4/templates/bs4/field.html
@@ -1,4 +1,4 @@1 -1 <div class="{{ form_group_class }} {% if check %}form-check{% endif %}">-1 1 <{{ fieldset|yesno:'fieldset,div' }} class="{{ form_group_class }} {% if check %}form-check{% endif %}"> 2 2 {% if check %} 3 3 {{ field }} 4 4 {% if show_label %} @@ -6,7 +6,11 @@ 6 6 {% endif %} 7 7 {% else %} 8 8 {% if show_label %}9 -1 <label {% ifequal show_label 'sr-only' %}class="sr-only"{% endifequal %} for="{{ field.id_for_label }}">{{ field.label }}</label>-1 9 {% if fieldset %} -1 10 <legend class="h6 {% ifequal show_label 'sr-only' %}sr-only{% endifequal %}">{{ field.label }}</legend> -1 11 {% else %} -1 12 <label {% ifequal show_label 'sr-only' %}class="sr-only"{% endifequal %} for="{{ field.id_for_label }}">{{ field.label }}</label> -1 13 {% endif %} 10 14 {% endif %} 11 15 {% if addon_before or addon_after %} 12 16 <div class="input-group"> @@ -32,4 +36,4 @@ 32 36 {% for error in field.errors %} 33 37 <small class="form-text text-danger">{{ error }}</small> 34 38 {% endfor %}35 -1 </div>-1 39 </{{ fieldset|yesno:'fieldset,div' }}>
diff --git a/django_bs4/templates/django/forms/widgets/multiwidget.html b/django_bs4/templates/django/forms/widgets/multiwidget.html
@@ -1,7 +1,7 @@1 -1 <div class="form-row">-1 1 <fieldset class="form-row"> 2 2 {% for widget in widget.subwidgets %} 3 3 <div class="col-sm {% if not forloop.last %}mb-2 mb-sm-0{% endif %}"> 4 4 {% include widget.template_name %} 5 5 </div> 6 6 {% endfor %}7 -1 </div>-1 7 </fieldset>
diff --git a/django_bs4/templatetags/bootstrap4.py b/django_bs4/templatetags/bootstrap4.py
@@ -51,12 +51,12 @@ def bootstrap_field( 51 51 form_group_class='form-group', 52 52 ): 53 53 widget = boundfield.field.widget -1 54 is_check = getattr(widget, 'input_type', None) in ['checkbox', 'radio'] -1 55 has_options = getattr(widget, 'option_template_name', None) 54 56 return { 55 57 'field': boundfield,56 -1 'check': (57 -1 getattr(widget, 'input_type', None) in ['checkbox', 'radio']58 -1 and not getattr(widget, 'option_template_name', None)59 -1 ),-1 58 'check': is_check and not has_options, -1 59 'fieldset': is_check and has_options, 60 60 'addon_before': addon_before, 61 61 'addon_after': addon_after, 62 62 'show_label': show_label,