© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•12mo ago•
6 replies
98.dev

Select Option Disabled Based on Another Field's Value

Code:

Select::make('status')
    ->options([
        'draft' => 'Draft',
        'reviewing' => 'Reviewing',
        'published' => 'Published',
    ])
    ->live(),

Select::make('name')
    ->options([
        'jack' => 'Jack',
        'bob' => 'Bob'
    ])
    ->disableOptionWhen(fn($get, $value) => $get('status') === 'published' && $value === 'bob')
    ->live()
    ->required(),
Select::make('status')
    ->options([
        'draft' => 'Draft',
        'reviewing' => 'Reviewing',
        'published' => 'Published',
    ])
    ->live(),

Select::make('name')
    ->options([
        'jack' => 'Jack',
        'bob' => 'Bob'
    ])
    ->disableOptionWhen(fn($get, $value) => $get('status') === 'published' && $value === 'bob')
    ->live()
    ->required(),


Expected Behaviour:

- When the
status
status
is set to
published
published
, the
Name
Name
field should disable the option
bob
bob
.
- Selecting
bob
bob
when the
status
status
is not
published
published
should be allowed, but if the
status
status
is changed to
published
published
,
bob
bob
should be
disabled
disabled
and should not remain selected.

Observed Behaviour

1. Set the
status
status
to any value except
published
published
.
2. Select name as
bob
bob
.
3. Change the
status
status
to
published
published
.
4. Notice that
bob
bob
is still selected and the record can still be saved with
bob
bob
as the selected value, even though the option should be disabled.

Complication:

- The issue I believe here is, when the
status
status
is changed to
published
published
, the form still allows
bob
bob
to be saved, even though the option is disabled.

Question:

- Should this behaviour be automatically handled by Filament (Disabling/Resetting the option dynamically based on the value of another field)?
- Or, do I need to manually validate the data when saving to ensure that
bob
bob
is not selected when
status
status
is set to
published
published
?
Solution
You’re not resetting the name field. So the name in the data is still bob. So you need to $set(‘name’, null) in the status afterStateUpdated() too.
Jump to solution
Filament banner
FilamentJoin
A powerful open source UI framework for Laravel • Build and ship admin panels & apps fast with Livewire
20,307Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

Update a field based on select value
FilamentFFilament / ❓┊help
2y ago
Conditionally display a section, based on another field's value
FilamentFFilament / ❓┊help
2y ago
Force select value based on a toggle option
FilamentFFilament / ❓┊help
11mo ago
Hiding a section based on Select field value
FilamentFFilament / ❓┊help
3y ago