FilamentF
Filament2y ago
Suky

Dinamically update options based on another input

so the question is pretty straight forward, is there a way to update the options of a select field based on another field?

so these options would be nice if I could add an where query
Forms\Components\Select::make('bundle_descriptor_id')
                            ->label('Bundle Descriptor')
                            ->searchable()
                            ->relationship('descriptor', 'name')
                            ->createOptionForm([
                                Forms\Components\TextInput::make('name')
                                    ->required(),
                            ])
                            ->options(function () {
                                return \App\Models\StreamingBundleDescriptor::all()->pluck('name', 'id')->toArray();
                            })
                            ->required(),

based on this input
 Forms\Components\Select::make('streaming_bundle_id')
                    ->label('Streaming Bundle')
                    ->searchable()
                    ->options(function () {
                        return \App\Models\StreamingBundle::all()->pluck('name', 'id')->toArray();
                    })
                    ->required(),
Solution
You need to use ->live() in such a case. Take a look in the docs to figure all related methods like ->afterStateUpdated()
https://filamentphp.com/docs/3.x/forms/advanced
Was this page helpful?