Skip to content

Field errors not displaying correctly because of <div id="id_fieldname_error"> wrapper in new version #763

@VVP04

Description

@VVP04

Hello,

After updating to the latest version of django-bootstrap5, my form field validation errors stopped being visible in the browser.

The HTML contains the error text, but it is not displayed to the user.

In the previous version, the rendered error looked like this (and displayed correctly):

Passwords do not match.

But in the new version, errors are wrapped inside an additional container:

Passwords do not match.

Because of this wrapper (

), the Bootstrap 5 .invalid-feedback styles are not applied as expected, so the message is invisible in the browser.

Questions:
Why was this wrapper added?
How can I make the error visible in the browser without downgrading to the old version?
Is there a recommended Bootstrap-compatible way to style errors with this new HTML structure?

Versions:

Django: 5.2.4

django-bootstrap5: 25.2

Bootstrap: 5.3.7

Example form:
class MyForm(forms.Form):
password = forms.CharField(widget=forms.PasswordInput)
password_confirm = forms.CharField(widget=forms.PasswordInput)

def clean(self):
    cleaned_data = super().clean()
    if cleaned_data.get("password") != cleaned_data.get("password_confirm"):
        self.add_error("password_confirm", "Passwords do not match")

Template:
{% load django_bootstrap5 %}

{% csrf_token %} {% bootstrap_form form %} Save

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions