filamentphp / filament

A collection of beautiful full-stack components for Laravel. The perfect starting point for your next app. Using Livewire, Alpine.js and Tailwind CSS.
https://filamentphp.com
MIT License
18.86k stars 2.93k forks source link

Bug: CheckboxList does not display descriptions when using an enum for dynamic options #14500

Closed standaniels closed 2 weeks ago

standaniels commented 3 weeks ago

Package

filament/filament

Package Version

v3.2.108

Laravel Version

v11.21.0

Livewire Version

v3.5.6

PHP Version

8.3.12

Problem description

When rendering a CheckboxList field with dynamic options where an enum is returned by the options closure, the descriptions are not displayed. This issue occurs even though the enum implements both HasDescription and HasLabel.

Code example:

enum Options: string implements HasDescription, HasLabel
{
    case FOO = 'foo';
    case BAR = 'bar';

    public function getDescription(): ?string
    {
        return match ($this) {
            self::FOO => 'Foo Description',
            self::BAR => 'Bar Description',
        };
    }

    public function getLabel(): ?string
    {
        return match ($this) {
            self::FOO => 'Foo Label',
            self::BAR => 'Bar Label',
        };
    }
}

///

class TestComponent extends Livewire
{
    public function form(Form $form): Form
    {
        return $form
            ->schema([
                CheckboxList::make('test')->options(fn () => Options::class),
            ]);
    }

Expected behavior

The descriptions (Foo Description and Bar Description) should be displayed below their respective labels (Foo Label and Bar Label) in the rendered form.

Steps to reproduce

  1. Render a form with a CheckboxList field
  2. Write a closure returning the options
  3. Return an enum class which implements HasLabel and HasDescription

Reproduction repository (issue will be closed if this is not valid)

https://github.com/standaniels/filament/tree/fix-descriptions-for-dynamic-options

Relevant log output

No response

Donate 💰 to fund this issue

Fund with Polar

danharrin commented 2 weeks ago

Per my comment in #14501