Multiple dependant fields / clearing on change

Hi all, I am trying to create a bunch of dependent fields where season_id depends on series_id, event_id then depends on season_id and session_id then depends on event_id! The method I have created works initially, but if I go back to edit the fields the selects retain the value. Is there a way I can force clear the value when one of the dependent field has changed? Here is my code:
Forms\Components\Section::make('Relationships')
->columns()
->schema([
Forms\Components\Select::make('series_id')
->live()
->relationship('series', 'name'),

Forms\Components\Select::make('season_id')
->live()
->disabled(fn ($get): bool => ! filled($get('series_id')))
->relationship(
'season',
'name',
fn ($get, $query) => $query->where('series_id', $get('series_id'))
),

Forms\Components\Select::make('event_id')
->live()
->disabled(fn ($get): bool => ! filled($get('season_id')))
->relationship(
'event',
'name',
fn ($get, $query) => $query->where('season_id', $get('season_id'))
),

Forms\Components\Select::make('session_id')
->live()
->disabled(fn ($get): bool => ! filled($get('event_id')))
->relationship(
'session',
'name',
fn ($get, $query) => $query->where('event_id', $get('event_id'))
),
]),
Forms\Components\Section::make('Relationships')
->columns()
->schema([
Forms\Components\Select::make('series_id')
->live()
->relationship('series', 'name'),

Forms\Components\Select::make('season_id')
->live()
->disabled(fn ($get): bool => ! filled($get('series_id')))
->relationship(
'season',
'name',
fn ($get, $query) => $query->where('series_id', $get('series_id'))
),

Forms\Components\Select::make('event_id')
->live()
->disabled(fn ($get): bool => ! filled($get('season_id')))
->relationship(
'event',
'name',
fn ($get, $query) => $query->where('season_id', $get('season_id'))
),

Forms\Components\Select::make('session_id')
->live()
->disabled(fn ($get): bool => ! filled($get('event_id')))
->relationship(
'session',
'name',
fn ($get, $query) => $query->where('event_id', $get('event_id'))
),
]),
Thanks!
No description
1 Reply
chrispage1
chrispage1OP6mo ago
Ah figured it out using afterStateUpdated
Forms\Components\Select::make('series_id')
->afterStateUpdated(function (Forms\Set $set) {
$set('season_id', null);
$set('event_id', null);
$set('session_id', null);
})
->relationship('series', 'name'),
Forms\Components\Select::make('series_id')
->afterStateUpdated(function (Forms\Set $set) {
$set('season_id', null);
$set('event_id', null);
$set('session_id', null);
})
->relationship('series', 'name'),
Thanks anyway!
Want results from more Discord servers?
Add your server