Skip to content

Add option to display label for checkbox/switch above the field.#1436

Open
mjauvin wants to merge 3 commits intodevelopfrom
label-placement
Open

Add option to display label for checkbox/switch above the field.#1436
mjauvin wants to merge 3 commits intodevelopfrom
label-placement

Conversation

@mjauvin
Copy link
Member

@mjauvin mjauvin commented Jan 8, 2026

Screenshot_20260108-145505 Chrome

Summary by CodeRabbit

  • New Features

    • Added configurable label visibility for checkbox and switch form fields through a new per-field showLabels setting, allowing control over whether labels appear above these field types.
  • Improvements

    • Form labels for checkbox and switch fields now respect individual field configuration instead of being universally hidden.
  • Style

    • Updated form styling to properly support conditional label visibility.

@mjauvin mjauvin self-assigned this Jan 8, 2026
@mjauvin mjauvin added the enhancement PRs that implement a new feature or substantial change label Jan 8, 2026
@coderabbitai
Copy link

coderabbitai bot commented Jan 8, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: af69012f-d731-4db8-a281-fd857a1bade1

📥 Commits

Reviewing files that changed from the base of the PR and between b1fbb6b and b42b18d.

📒 Files selected for processing (11)
  • modules/backend/classes/FormField.php
  • modules/system/assets/js/build/manifest.js
  • modules/system/assets/js/build/system.debug.js
  • modules/system/assets/js/build/system.js
  • modules/system/assets/js/snowboard/build/snowboard.base.debug.js
  • modules/system/assets/js/snowboard/build/snowboard.base.js
  • modules/system/assets/js/snowboard/build/snowboard.data-attr.js
  • modules/system/assets/js/snowboard/build/snowboard.extras.js
  • modules/system/assets/js/snowboard/build/snowboard.request.js
  • modules/system/assets/ui/less/form.less
  • modules/system/assets/ui/storm.css
✅ Files skipped from review due to trivial changes (3)
  • modules/system/assets/js/snowboard/build/snowboard.request.js
  • modules/system/assets/js/snowboard/build/snowboard.extras.js
  • modules/system/assets/js/snowboard/build/snowboard.data-attr.js
🚧 Files skipped from review as they are similar to previous changes (1)
  • modules/backend/classes/FormField.php

Walkthrough

A new showLabels boolean property is added to the FormField class to control label visibility for checkbox, switch, and section field types. The form widget's label rendering logic is updated to respect this per-field configuration, replacing the previous universal suppression of labels for these types. Form partials and CSS styling are modified accordingly to conditionally render labels and help text.

Changes

Cohort / File(s) Summary
Core Property Addition
modules/backend/classes/FormField.php
Adds public showLabels property and includes it in evalConfig so it can be set via field config.
Widget Logic
modules/backend/widgets/Form.php
showFieldLabels() now returns the field's showLabels value for checkbox, switch, and section types (defaults to false when unset).
Field Rendering (checkbox)
modules/backend/widgets/form/partials/_field_checkbox.php
Label class and label text rendering are conditional on field->showLabels; help/comment block is shown only when labels are suppressed and a comment exists.
Field Rendering (switch)
modules/backend/widgets/form/partials/_field_switch.php
Label and help/comment rendering gated by field->showLabels, hiding comment when showLabels is true.
Styling
modules/system/assets/ui/less/form.less
Adjusts .custom-checkbox label selector to exclude .show-labels so required indicator asterisk is not shown when labels are enabled.
Built JS / Snowboard bundles
modules/system/assets/js/.../build/*.js, modules/system/assets/js/snowboard/build/*.js
Reordered/rewrapped webpack module entries and minor callback refactors (arrow/anon function style). No behavioral API changes detected; mostly bundle/module-ID rearrangements and stylistic edits.
Build manifest
modules/system/assets/js/build/manifest.js
Minor syntactic callback adjustments in the build manifest.

Sequence Diagram(s)

sequenceDiagram
  participant Config as Field Config
  participant Widget as Form Widget
  participant Field as FormField
  participant Partial as Template Partial
  participant Browser as Browser/CSS

  Config->>Widget: provide field config (includes showLabels)
  Widget->>Field: evalConfig() -> set showLabels
  Widget->>Partial: renderField(field)
  Partial->>Field: check field.showLabels
  alt showLabels == true
    Partial->>Browser: render input without label (add .show-labels class)
    Browser->>Browser: CSS hides asterisk for .show-labels
  else showLabels == false
    Partial->>Browser: render label and help text
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 7.41% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Add option to display label for checkbox/switch above the field' directly and clearly describes the main change: introducing a new configuration option (showLabels) that allows conditional label display for checkbox and switch fields.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch label-placement

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (2)
modules/backend/classes/FormField.php (1)

183-186: Update documentation to include 'section' field type and consider adding type hints.

The docblock mentions "checkbox/switch fields" but the implementation in modules/backend/widgets/Form.php (line 1158) also applies this property to 'section' field types. Additionally, consider adding a type hint and explicit default value for better type safety and clarity.

📝 Suggested improvements
 /**
- * @var bool Should the field's label for checkbox/switch fields be displayed above the field.
+ * @var bool|null Should the field's label for checkbox/switch/section fields be displayed above the field.
+ * When true, the label is rendered above the field by the form widget.
+ * When false or null (default), the label is rendered inline by the field partial.
  */
-public $showLabels;
+public $showLabels = null;
modules/backend/widgets/form/partials/_field_checkbox.php (1)

18-22: Consider accessibility implications of dual label elements.

When showLabels is true, there are effectively two <label> elements associated with the same input:

  1. A label with text content rendered above the field by the form widget
  2. An empty label element here (with show-labels class)

While this maintains the HTML structure, having two labels for one input may have semantic implications. Consider verifying that screen readers handle this correctly and whether ARIA attributes might improve clarity.

If you'd like to verify the accessibility of this implementation, consider testing with screen readers (NVDA, JAWS, VoiceOver) to ensure the dual-label structure doesn't cause confusion.

📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8a7f74b and b1fbb6b.

📒 Files selected for processing (6)
  • modules/backend/classes/FormField.php
  • modules/backend/widgets/Form.php
  • modules/backend/widgets/form/partials/_field_checkbox.php
  • modules/backend/widgets/form/partials/_field_switch.php
  • modules/system/assets/ui/less/form.less
  • modules/system/assets/ui/storm.css
🧰 Additional context used
🧬 Code graph analysis (2)
modules/backend/widgets/form/partials/_field_checkbox.php (1)
modules/backend/classes/FormField.php (2)
  • getId (604-622)
  • comment (361-371)
modules/backend/widgets/form/partials/_field_switch.php (1)
modules/backend/classes/FormField.php (2)
  • getId (604-622)
  • comment (361-371)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (9)
  • GitHub Check: windows-latest / PHP 8.4
  • GitHub Check: ubuntu-latest / PHP 8.4
  • GitHub Check: ubuntu-latest / PHP 8.1
  • GitHub Check: ubuntu-latest / PHP 8.2
  • GitHub Check: windows-latest / PHP 8.3
  • GitHub Check: windows-latest / PHP 8.2
  • GitHub Check: windows-latest / PHP 8.1
  • GitHub Check: ubuntu-latest / PHP 8.3
  • GitHub Check: windows-latest / JavaScript
🔇 Additional comments (5)
modules/backend/classes/FormField.php (1)

287-302: LGTM: showLabels properly integrated into config processing.

The addition of showLabels to the evalConfig array correctly enables this property to be set via field configuration, maintaining consistency with other form field properties.

modules/system/assets/ui/less/form.less (1)

125-139: LGTM: CSS correctly excludes required asterisk for labels in label-above mode.

The :not(.show-labels) selector appropriately prevents the required asterisk from appearing on the inline label element when showLabels is true. In this mode, the asterisk appears on the label rendered above by the form widget, and the inline label element is empty and should not display an asterisk.

modules/backend/widgets/form/partials/_field_checkbox.php (1)

24-26: LGTM: Help text rendering logic is consistent.

The conditional rendering of help text matches the pattern used in the switch partial, correctly showing help text only when labels are rendered inline (showLabels is false).

modules/backend/widgets/Form.php (1)

1156-1167: LGTM: Per-field label visibility control implemented correctly.

The change from return false; to return $field->showLabels ?? false; enables per-field configuration while maintaining backward compatibility. The null coalescing operator ensures existing forms continue to work with the default inline label behavior.

The implementation correctly:

  • Applies to checkbox, switch, and section field types
  • Preserves widget field behavior (which has its own showLabels property)
  • Defaults to false when showLabels is not explicitly set
  • Integrates with the FormField.showLabels property and partial rendering logic
modules/backend/widgets/form/partials/_field_switch.php (1)

14-19: Code logic is correct and properly integrated with the form widget.

The conditional rendering in this partial correctly hides the label and help text when showLabels is false. When showLabels is true, the main form widget partial (_field.php) takes over and uses the commentPosition property to render help text either above or below the field, ensuring help text is never lost.

@mjauvin mjauvin requested a review from LukeTowers January 8, 2026 20:00
@mjauvin mjauvin changed the title Changes to permit displaying label for checkbox/switch above the field Changes to display label for checkbox/switch above the field. Jan 10, 2026
@mjauvin mjauvin changed the title Changes to display label for checkbox/switch above the field. Add option to display label for checkbox/switch above the field. Mar 10, 2026
@mjauvin
Copy link
Member Author

mjauvin commented Mar 10, 2026

Note: I bear no responsibility for all those js assets that got recompiled aven though I did not make any change to their dependencies.

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

Labels

enhancement PRs that implement a new feature or substantial change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant