Skip to content

renderers: keep the classes a widget template sets - #896

Open
dyve wants to merge 2 commits into
mainfrom
fix/894-preserve-widget-classes
Open

dyve wants to merge 2 commits into
mainfrom
fix/894-preserve-widget-classes

Conversation

@dyve

@dyve dyve commented Sep 21, 2026

Copy link
Copy Markdown
Member

list_to_class assigned the enclosing div's class attribute outright, so any class the widget's own template set was discarded. RadioSelectButtonGroup sets btn-group btn-group-toggle, which is what makes it a button group, so rendering it through bootstrap_field produced neither a button group nor plain radios. data-toggle="buttons" survived, because only the class was overwritten, leaving Bootstrap's toggle JavaScript wired to nothing.

The class is now added to what the widget already set. Django's RadioSelect and CheckboxSelectMultiple templates emit no class on that element, so this is a no-op for every widget shipped with Django: I diffed the rendered output of category1 through category4, at default and small size, and it is byte-identical. Only category5, the custom widget, changes. There is a test for each half of that.

I also dropped the follow-up soup.find("div", {"class": classes}). It re-found the element already in hand, and it only worked as long as the class was assigned rather than appended, so it would have quietly stopped matching after this change.

One thing this does not address: the enclosing div now reads btn-group btn-group-toggle radio radio-success. The radio radio-success part is noise on a button group, but it is what post_widget_render passes for every RadioSelect subclass, and suppressing it per widget is a wider change than this fix.

Fixes #894

🤖 Generated with Claude Code

list_to_class assigned the enclosing div's class attribute outright, so
any class the widget's own template set was discarded. RadioSelectButtonGroup
sets btn-group btn-group-toggle, which is what makes it a button group, so
rendering it through bootstrap_field produced neither a button group nor
plain radios, while data-toggle="buttons" survived and left Bootstrap's
toggle JavaScript wired to nothing.

The class is now added to what the widget already set. Django's RadioSelect
and CheckboxSelectMultiple templates emit no class on that element, so
output for every widget shipped with Django is byte-identical; only custom
widget templates that set a class are affected, which is the case this fixes.

The follow-up lookup of the same div by its new class string is gone too. It
re-found the element that was already in hand and only worked as long as the
class was assigned rather than appended.

Fixes #894

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@coveralls

coveralls commented Sep 21, 2026 •

Copy link
Copy Markdown

Coverage Status

coverage: 87.091% (+0.06%) from 87.035% — fix/894-preserve-widget-classes into main

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

RadioSelectButtonGroup does not render as a button group through bootstrap_field

2 participants