Select Option Disabled Based on Another Field's Value
Code:
Expected Behaviour:
- When the
status
is set to published
, the Name
field should disable the option bob
.
- Selecting bob
when the status
is not published
should be allowed, but if the status
is changed to published
, bob
should be disabled
and should not remain selected.
Observed Behaviour
1. Set the status
to any value except published
.
2. Select name as bob
.
3. Change the status
to published
.
4. Notice that bob
is still selected and the record can still be saved with bob
as the selected value, even though the option should be disabled.
Complication:
- The issue I believe here is, when the status
is changed to published
, the form still allows 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
is not selected when status
is set to published
?Solution:Jump to 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.
3 Replies

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.
Thank you @awcodes 🫡