Skip to content

Add swapLabelAndValue() option to BooleanField - #7773

Open
ERuban wants to merge 1 commit into
EasyCorp:5.xfrom
ERuban:add_boolean_label_swap_option
Open

Add swapLabelAndValue() option to BooleanField#7773
ERuban wants to merge 1 commit into
EasyCorp:5.xfrom
ERuban:add_boolean_label_swap_option

Conversation

@ERuban

@ERuban ERuban commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Since 4.8.0, boolean fields on the detail page swap the usual label <-> value order (#5977). The reasoning is documented in the CSS: the label is usually a medium-long string and the value is always tiny.

This has been a recurring pain point: #6018 (open since 2023, priority: important, 16 comments) collects several requests and at least three different sets of user-land CSS workarounds. The thread doesn't ask to revert the default — it asks for an opt-in way to restore the regular order ("I am still for having some opt-in possibility for this swap").

This PR adds that option, following the style of the existing renderAsSwitch() / hideValueWhenTrue() options:

yield BooleanField::new('active')->swapLabelAndValue(false);

The default behavior doesn't change. The option defaults to true (current behavior). When set to false, the configurator adds a field-boolean-no-swap CSS class and the existing swap rules are scoped with :not(.field-boolean-no-swap) — so a disabled swap simply renders the field like every other field, with no counter-rules fighting specificity.

Includes tests, documentation and rebuilt assets (only the CSS bundle changed).

Closes #6018

@ERuban

ERuban commented Aug 3, 2026

Copy link
Copy Markdown
Contributor Author

A possible follow-up, if there's interest: #6018 also asked for a way to configure this once for the whole backend ("or as an alternative add a setting in the Dashboard/Crud config classes"). This could be a Crud option set in configureCrud() (dashboard-wide or per CRUD controller), with the field-level swapLabelAndValue() overriding it - the same cascade that Crud::setThousandsSeparator() and the number fields already use.

Happy to send that as a separate PR if you think it fits - this one stays field-level only to keep it small.

@ERuban
ERuban force-pushed the add_boolean_label_swap_option branch from df3f727 to ae61ae2 Compare August 3, 2026 20:56
@ERuban
ERuban force-pushed the add_boolean_label_swap_option branch from ae61ae2 to e772b79 Compare August 5, 2026 12:26
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.

BooleanField suddenly reversed

1 participant