© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•5mo ago•
3 replies
Mark Chaney

Selection when $state is null

This seems dirty, but works. Is this the only way automatically select an option when the state is null? If i do not do this string workaround, nothing gets selected when the state is null.
->options([
    '' => 'None',
    '1' => '1x',
    '1.5' => '1.5x',
    '2' => '2x',
    '2.5' => '2.5x',
    '3' => '3x',
])
->formatStateUsing(fn ($state) => $state ?? '')
->dehydrateStateUsing(fn ($state) => $state === '' ? null : $state)
->options([
    '' => 'None',
    '1' => '1x',
    '1.5' => '1.5x',
    '2' => '2x',
    '2.5' => '2.5x',
    '3' => '3x',
])
->formatStateUsing(fn ($state) => $state ?? '')
->dehydrateStateUsing(fn ($state) => $state === '' ? null : $state)
I would prefer to just do
->options([
    null => 'None',
    '1' => '1x',
    '1.5' => '1.5x',
    '2' => '2x',
    '2.5' => '2.5x',
    '3' => '3x',
])
->options([
    null => 'None',
    '1' => '1x',
    '1.5' => '1.5x',
    '2' => '2x',
    '2.5' => '2.5x',
    '3' => '3x',
])
Filament banner
FilamentJoin
A powerful open source UI framework for Laravel • Build and ship admin panels & apps fast with Livewire
20,307Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

InfoList icon not showing when state is null
FilamentFFilament / ❓┊help
3y ago
TextEntry when value is null
FilamentFFilament / ❓┊help
2y ago
Null state for table column
FilamentFFilament / ❓┊help
3y ago
TernaryFilter null state is broken after refreshing and reseting filters.
FilamentFFilament / ❓┊help
3y ago