-
-
Notifications
You must be signed in to change notification settings - Fork 93
Open
Description
Issue
When trying to render a checkbox form field with the label being an empty string, instead of seeing the rendered checkbox we see escaped html.
Versions
- Django: 4.2.24
- django-bootstrap5: 25.1
- Bootstrap: 5.3.0
Steps to reproduce
Simple steps to reproduce issue.
# forms.py
from django import forms
class TestForm(forms.Form):
agree = forms.BooleanField(label='', required=False){# template.html #}
{% load django_bootstrap5 %}
<form method="post">
{% csrf_token %}
{% bootstrap_field form.agree %}
<button type="submit">Submit</button>
</form># views.py
from django.shortcuts import render
from .forms import TestForm
def test_view(request):
form = TestForm()
return render(request, "template.html", {"form": form})My thoughts
| def get_label_html(self, horizontal=False): |
If label_html = "", this method just returns label_html. Then in:
| def render(self): |
If we have a checkbox field, this code in render() might not return safe html with the field = field + label:
if self.field_before_label():
label = self.get_label_html()
field = field + label
label = mark_safe("")
horizontal_class = merge_css_classes(self.horizontal_field_class, self.horizontal_field_offset_class)Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels