Enum Class name in Frontend

While checking the frontend code found out that the enum class name in default does show up in the frontend. Is that normal behavior? So ->default(EventStatus::Published->value) will just output Published value as a string in the frontend But ->default(EventStatus::Published) will have "App\Enums\EventStatus" in the frontend code. I'm new to all livewire/filament so pardon if that's a stupid question. I just don't like to leak folder structure, although that's probably safe.
5 Replies
Tieme
Tieme11mo ago
What field is it? Text field, Select field? Can you share your enum class and field where default is set?
pozitiveman
pozitivemanOP11mo ago
@Tieme
ToggleButtons::make('type') ->options(EventType::class) ->default(EventType::Standard), Select::make('status') ->options(EventStatus::class) ->default(EventStatus::Published), *I have other parameters for Select and ToggleButton, but non of them made a difference. use Filament\Support\Contracts\HasLabel; enum EventStatus: string implements HasLabel { case Draft = 'draft'; case Published = 'published'; public function getLabel(): ?string { return $this->name; } } * Also adding or excluding HasLabel interface did not make any difference.
awcodes
awcodes11mo ago
What do you mean by “frontend” in this case. If you’re using a cast for the enum then you have to expect the model’s value for that field to be the enum. How you handle or use that is up to your front end.
pozitiveman
pozitivemanOP11mo ago
@awcodes By frontend I mean the response from the server. It feels strange that I see App\\Enums\\EventStatus in the response, which outputs the enum class name and the file path to the end user. My expectation was that it would just cast the value of the enum, without exposing enum class file name. My apologize, I'm still figuring our how all this livewire and filament works.
awcodes
awcodes11mo ago
Think about it like a DateTime cast. It returns the class instance not the value. That’s the nature of a cast. But if you are rendering it then there’s no real risk of exposure. In the rendering you can call->value on it or even use a match case on it to render whatever the view needs.
Want results from more Discord servers?
Add your server