Select Option Disabled Based on Another Field's Value
Code:
Expected Behaviour:
Expected Behaviour:
- When the
statusis set topublished, theNamefield should disable the optionbob. - Selecting
bobwhen thestatusis notpublishedshould be allowed, but if thestatusis changed topublished,bobshould bedisabledand should not remain selected.
- Set the
statusto any value exceptpublished. - Select name as
bob. - Change the
statustopublished. - Notice that
bobis still selected and the record can still be saved withbobas the selected value, even though the option should be disabled.
- The issue I believe here is, when the
statusis changed topublished, the form still allowsbobto be saved, even though the option is disabled.
- 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
bobis not selected whenstatusis set topublished?
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.