django-bs

Bootstrap integration for django using widget templates
git clone https://git.ce9e.org/django-bs.git

commit
e6bc74869d2803df140025989421484805393b7a
parent
bad4c1fda498aa5f2fdf4c194f4f4d8ae28b3bf2
Author
Tobias Bengfort <tobias.bengfort@posteo.de>
Date
2025-09-15 15:03
support required_css_class

The django style, where it is defined on the form and applied to the
label element.

Not to be confused with the option of the same name in
django-bootstrap5, which is defined in the template and applied to the
wrapper.

Diffstat

M django_bs/templates/bs/field.html 6 +++---
M example/forms.py 1 +

2 files changed, 4 insertions, 3 deletions


diff --git a/django_bs/templates/bs/field.html b/django_bs/templates/bs/field.html

@@ -1,12 +1,12 @@
    1     1 <{{ fieldset|yesno:'fieldset,div' }} class="{{ form_group_class }} {% if check %}form-check{% endif %}">
    2     2     {% if check %}
    3     3         {{ field }}
    4    -1         <label for="{{ field.id_for_label }}" class="form-check-label {% if not show_label %}visually-hidden{% endif %}">{{ field.label }}</label>
   -1     4         <label for="{{ field.id_for_label }}" class="form-check-label {% if field.field.required %}{{ field.form.required_css_class }}{% endif %} {% if not show_label %}visually-hidden{% endif %}">{{ field.label }}</label>
    5     5     {% else %}
    6     6         {% if fieldset %}
    7    -1             <legend class="form-label fs-6 {% if not show_label %}visually-hidden{% endif %}">{{ field.label }}</legend>
   -1     7             <legend class="form-label fs-6 {% if field.field.required %}{{ field.form.required_css_class }}{% endif %} {% if not show_label %}visually-hidden{% endif %}">{{ field.label }}</legend>
    8     8         {% else %}
    9    -1             <label class="form-label {% if not show_label %}visually-hidden{% endif %}" for="{{ field.id_for_label }}">{{ field.label }}</label>
   -1     9             <label class="form-label {% if field.field.required %}{{ field.form.required_css_class }}{% endif %} {% if not show_label %}visually-hidden{% endif %}" for="{{ field.id_for_label }}">{{ field.label }}</label>
   10    10         {% endif %}
   11    11         {% if addon_before or addon_after %}
   12    12             <div class="input-group">

diff --git a/example/forms.py b/example/forms.py

@@ -28,6 +28,7 @@ class ExampleForm(forms.Form):
   28    28     )
   29    29     date = forms.DateField(widget=forms.SelectDateWidget())
   30    30     date_time = forms.SplitDateTimeField()
   -1    31     required_css_class = 'required'
   31    32 
   32    33     def clean(self):
   33    34         cleaned_data = super().clean()