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'))
        ),
]),


Thanks!
image.png
Was this page helpful?