FilamentF
Filament12mo ago
morty

Dependent select without parent being saved to the database

I have a simple form based on a WorkOrder. A WorkOrder belongs to an Equipment. An Equipment belongs to a Location. Therefore, a WorkOrder belongs to a location through an Equipment.

I have a dependent select working for the most part:

Forms\Components\Select::make('location_id')
    ->label('Location')
    ->options(...)
    ->live()
    ->dehydrated(false)
    ->afterStateUpdated(fn (Forms\Set $set): null => $set('equipment_id', null))

Forms\Components\Select::make('equipment_id')
    ->label('Equipment')
    ->options(fn (Forms\Get $get): array => Equipment::query()->...),


My problem is on form hydration though when editing the WorkOrder. Since there is no location_id on the WorkOrder table, it obviously doesn't fill the location. I need to somehow fill the location based on the selected equipment instead and that's where I'm stuck. Any ideas?
CleanShot_2025-01-09_at_08.54.42.png
Was this page helpful?